Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscribe change not Working When App is Closed #130

Open
krisnapy opened this issue Jan 23, 2025 · 3 comments
Open

Subscribe change not Working When App is Closed #130

krisnapy opened this issue Jan 23, 2025 · 3 comments

Comments

@krisnapy
Copy link

Hello,

I've encountered an issue where the subscribe change functionality does not seem to work when the app is closed. I've already ensured that the following settings are enabled:

  1. HealthKit Background Delivery
  2. Background Fetch
  3. Background Processing
  4. Background Notification

Despite these configurations, changes are not being delivered as expected when the app is completely closed. Is there an additional step or configuration I might have missed to enable background HealthKit updates effectively?

const initAppleHealthKit = async () => {
  let unsubscribe: any = null

  try {
    await HealthKit.requestAuthorization(AUTHORIZATION_OPTIONS)
    await HealthKit.enableBackgroundDelivery(HKWorkoutTypeIdentifier, HKUpdateFrequency.immediate)

    unsubscribe = await HealthKit.subscribeToChanges(HKWorkoutTypeIdentifier, () =>
      BackgroundService.start(getWorkoutSamples, {
        taskName: 'ImportWorkout',
        taskTitle: t('Import workout...'),
        taskDesc: t('Please wait for the import workout to finish.'),
        taskIcon: {
          name: 'ic_notification',
          type: 'drawable',
        },
        color: palette.brandPrimary,
      })
    )
  } catch (error: any) {
    handleGenericError(error)
  }

  return () => unsubscribe()
}
@robertherber
Copy link
Member

Is this potentially a duplicate of #106?

@krisnapy
Copy link
Author

Thank you for your response!

Just to clarify, the package works fine when the app is in the background, as long as the app is not completely closed or killed.

@robertherber
Copy link
Member

@krisnapy Thanks for clarifying! I think this is probably a limitation on Apples side, they tend to restrict background tasks in general when an app has been forcefully killed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants