Permission Handling

Required Permissions

The required permissions for the individual services vary according to the platform type. See the sections Permissions Handling for iOS and Android respectively.

Missing required and optional permissions will be reported by the SDK through the MoveServiceFailure and MoveServiceWarning listeners and listed individually so there is no need for the application to do it's own permission checks except during the onboarding process where user permission must be queried.

In best practice, this onboarding step is performed before any setup of the SDK happens, but permission changes at any later point in time is possible.

If permission checks happen at a later point make sure to call the MoveSdk.resolveError() function to ensure a timely activation of the affected services.

Special Permissions

Due to the fact that some permission requests are not available directly from react native, the SDK offers an api that can be used to request the necessary permissions and check the status of those permissions:

Shared

Asks for the Steps permission for Health service:

MoveSdk.requestHealthPermissions(): Promise<boolean>

Before using requestHealthPermissions() in Android make sure you registered permission handler in your activity and added corresponding intents to AndroidManifest!

In your MainActivity class:

override fun onCreate(savedInstanceState: Bundle?) {
    // ...
    NativeMoveSdkWrapper.getInstance(this.applicationContext).registerRequestPermissionLauncher(this)
    // ...
    super.onCreate(null)
}

In AndroidManifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
  <!--Other permissions-->
  <!-- ... -->
  <uses-permission android:name="android.permission.health.READ_HEALTH_DATA_IN_BACKGROUND"/>
  <uses-permission android:name="android.permission.health.READ_STEPS"/>
  <application android:name=".MainApplication">
    <activity android:name=".MainActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:exported="true" android:screenOrientation="portrait">
      <!--Other intents-->
      <!-- ... -->
      <!--Intent filters for Health Connect-->
      <intent-filter>
        <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE"/>
        <category android:name="android.intent.category.HEALTH_PERMISSIONS"/>
      </intent-filter>
      <intent-filter>
        <action android:name="android.intent.action.VIEW_PERMISSION_USAGE"/>
        <category android:name="android.intent.category.HEALTH_PERMISSIONS"/>
      </intent-filter>
      <!--Intent filters for Health Connect-->
    </activity>
  </application>
</manifest>

Android

Draw Overlays

Ask for draw over other apps permission:

MoveSdk.requestDrawOverlaysPermission(): void

Check if draw over other apps permission is granted:

MoveSdk.canDrawOverlays(): Promise<boolean>

Ignoring Battery Optimisation

Ask for ignoring battery optimisation for this app:

MoveSdk.requestAppIgnoringBatteryOptimization(): void

Check if battery optimisation is ignored for this app:

MoveSdk.isAppIgnoringBatteryOptimization(): Promise<boolean>

iOS

Motion Permission

ios.permission.MOTION is available directly from react native, but requesting this permission via react native on simulators could be problematic. This method helps to request motion permission on simulators:

MoveSdk.requestMotionPermission(): void

Expo

If you are generating your project files with expo make sure to add the necessary capabilities to your expo config. See https://docs.expo.dev/build-reference/ios-capabilities/

Example:

expo: {
	...
	ios: {
		...
		infoPlist: {
			NSLocationAlwaysAndWhenInUseUsageDescription: '...',
			NSLocationAlwaysUsageDescription: '...',
			NSLocationWhenInUseUsageDescription: '...',
			NSMotionUsageDescription: '...',
			NSLocationTemporaryUsageDescriptionDictionary: {
				'LOCATION-ACCURACY': '...',
			},
			UIBackgroundModes: ['location', 'remote-notification'],
			NSBluetoothAlwaysUsageDescription: '...',
			NSHealthShareUsageDescription: '...',
		},
		entitlements: {
			'com.apple.developer.healthkit': true,
			'com.apple.developer.healthkit.background-delivery': true,
		},
		...
	...
},

Last updated