# Permission Handling

## Required Permissions

The required permissions for the individual services vary according to the platform type. See the sections *Permissions Handling* for [iOS](https://docs.movesdk.com/move-platform/sdk/appendix/ios/permission-handling) and [Android](https://docs.movesdk.com/move-platform/sdk/appendix/android/permission-handling) 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.

{% hint style="warning" %}
Due to Apple's static code analysis additional strings must be configured in the *Info.plist* to pass validation when uploading to the *AppStore*`and`*Testflight* even when this feature is not used. See section [iOS Permission Handling](https://docs.movesdk.com/move-platform/sdk/ios/permission-handling#bluetooth-permission) for details.

*Move SDK 2.15*: Health permissions/entitlements are only required if MoveSDKHealth extension framework is used.
{% endhint %}

## 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:

```typescript
MoveSdk.requestHealthPermissions(): Promise<boolean>
```

{% hint style="info" %}
Before using requestHealthPermissions() in Android make sure you registered permission handler in your activity and added corresponding intents to AndroidManifest!
{% endhint %}

In your MainActivity class:

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

In AndroidManifest:

```xml
<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:

```typescript
MoveSdk.requestDrawOverlaysPermission(): void
```

Check if draw over other apps permission is granted:

```typescript
MoveSdk.canDrawOverlays(): Promise<boolean>
```

#### Ignoring Battery Optimisation

Ask for ignoring battery optimisation for this app:

```typescript
MoveSdk.requestAppIgnoringBatteryOptimization(): void
```

Check if battery optimisation is ignored for this app:

```typescript
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:

```typescript
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:

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