Commit 1ece0281 authored by Ryan Eberhardt's avatar Ryan Eberhardt

Add iOS checkPermissions

Add a checkPermissions function allowing the app to determine what
notification permissions the user has granted. The function returns a
promise resolving to an object with permission info.
parent 9dbc7268
...@@ -185,6 +185,16 @@ class App extends Component { ...@@ -185,6 +185,16 @@ class App extends Component {
When you have the device token, POST it to your server and register the device in your notifications provider (Amazon SNS, Azure, etc.). When you have the device token, POST it to your server and register the device in your notifications provider (Amazon SNS, Azure, etc.).
You can check if the user granted permissions by calling `checkPermissions()`:
```javascript
NotificationsIOS.checkPermissions().then((currentPermissions) => {
console.log('Badges enabled: ' + !!currentPermissions.badge);
console.log('Sounds enabled: ' + !!currentPermissions.sound);
console.log('Alerts enabled: ' + !!currentPermissions.alert);
});
```
### Android ### Android
The React-Native code equivalent on Android is: The React-Native code equivalent on Android is:
......
...@@ -562,4 +562,14 @@ RCT_EXPORT_METHOD(isRegisteredForRemoteNotifications:(RCTPromiseResolveBlock)res ...@@ -562,4 +562,14 @@ RCT_EXPORT_METHOD(isRegisteredForRemoteNotifications:(RCTPromiseResolveBlock)res
resolve(@(ans)); resolve(@(ans));
} }
RCT_EXPORT_METHOD(checkPermissions:(RCTPromiseResolveBlock) resolve
reject:(RCTPromiseRejectBlock) reject) {
UIUserNotificationSettings *currentSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
resolve(@{
@"badge": @((currentSettings.types & UIUserNotificationTypeBadge) > 0),
@"sound": @((currentSettings.types & UIUserNotificationTypeSound) > 0),
@"alert": @((currentSettings.types & UIUserNotificationTypeAlert) > 0),
});
}
@end @end
...@@ -212,4 +212,8 @@ export default class NotificationsIOS { ...@@ -212,4 +212,8 @@ export default class NotificationsIOS {
static isRegisteredForRemoteNotifications() { static isRegisteredForRemoteNotifications() {
return NativeRNNotifications.isRegisteredForRemoteNotifications(); return NativeRNNotifications.isRegisteredForRemoteNotifications();
} }
static checkPermissions() {
return NativeRNNotifications.checkPermissions();
}
} }
...@@ -68,7 +68,8 @@ describe("NotificationsIOS", () => { ...@@ -68,7 +68,8 @@ describe("NotificationsIOS", () => {
cancelLocalNotification: nativeCancelLocalNotification, cancelLocalNotification: nativeCancelLocalNotification,
cancelAllLocalNotifications: nativeCancelAllLocalNotifications, cancelAllLocalNotifications: nativeCancelAllLocalNotifications,
setBadgesCount: nativeSetBadgesCount, setBadgesCount: nativeSetBadgesCount,
isRegisteredForRemoteNotifications: nativeIsRegisteredForRemoteNotifications isRegisteredForRemoteNotifications: nativeIsRegisteredForRemoteNotifications,
checkPermissions: nativeCheckPermissions,
} }
}, },
NativeAppEventEmitter: { NativeAppEventEmitter: {
...@@ -309,4 +310,12 @@ describe("NotificationsIOS", () => { ...@@ -309,4 +310,12 @@ describe("NotificationsIOS", () => {
}); });
}); });
describe("Check permissions ", () => {
it("should call native check permissions", () => {
NotificationsIOS.checkPermissions();
expect(nativeCheckPermissions).to.have.been.calledWith();
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment