Commit 77bce6a6 authored by Ran Greenberg's avatar Ran Greenberg Committed by GitHub

Merge pull request #95 from reberhardt7/master

Add iOS checkPermissions
parents 9dbc7268 24eee3b5
...@@ -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();
}
} }
...@@ -29,7 +29,8 @@ describe("NotificationsIOS", () => { ...@@ -29,7 +29,8 @@ describe("NotificationsIOS", () => {
nativeCancelLocalNotification, nativeCancelLocalNotification,
nativeCancelAllLocalNotifications, nativeCancelAllLocalNotifications,
nativeSetBadgesCount, nativeSetBadgesCount,
nativeIsRegisteredForRemoteNotifications; nativeIsRegisteredForRemoteNotifications,
nativeCheckPermissions;
let NotificationsIOS, NotificationAction, NotificationCategory; let NotificationsIOS, NotificationAction, NotificationCategory;
let someHandler = () => {}; let someHandler = () => {};
...@@ -51,6 +52,7 @@ describe("NotificationsIOS", () => { ...@@ -51,6 +52,7 @@ describe("NotificationsIOS", () => {
nativeCancelAllLocalNotifications = sinon.spy(); nativeCancelAllLocalNotifications = sinon.spy();
nativeSetBadgesCount = sinon.spy(); nativeSetBadgesCount = sinon.spy();
nativeIsRegisteredForRemoteNotifications = sinon.spy(); nativeIsRegisteredForRemoteNotifications = sinon.spy();
nativeCheckPermissions = sinon.spy();
let libUnderTest = proxyquire("../index.ios", { let libUnderTest = proxyquire("../index.ios", {
"uuid": { "uuid": {
...@@ -68,7 +70,8 @@ describe("NotificationsIOS", () => { ...@@ -68,7 +70,8 @@ describe("NotificationsIOS", () => {
cancelLocalNotification: nativeCancelLocalNotification, cancelLocalNotification: nativeCancelLocalNotification,
cancelAllLocalNotifications: nativeCancelAllLocalNotifications, cancelAllLocalNotifications: nativeCancelAllLocalNotifications,
setBadgesCount: nativeSetBadgesCount, setBadgesCount: nativeSetBadgesCount,
isRegisteredForRemoteNotifications: nativeIsRegisteredForRemoteNotifications isRegisteredForRemoteNotifications: nativeIsRegisteredForRemoteNotifications,
checkPermissions: nativeCheckPermissions
} }
}, },
NativeAppEventEmitter: { NativeAppEventEmitter: {
...@@ -108,6 +111,7 @@ describe("NotificationsIOS", () => { ...@@ -108,6 +111,7 @@ describe("NotificationsIOS", () => {
nativeCancelLocalNotification.reset(); nativeCancelLocalNotification.reset();
nativeCancelAllLocalNotifications.reset(); nativeCancelAllLocalNotifications.reset();
nativeIsRegisteredForRemoteNotifications.reset(); nativeIsRegisteredForRemoteNotifications.reset();
nativeCheckPermissions.reset();
}); });
after(() => { after(() => {
...@@ -124,6 +128,7 @@ describe("NotificationsIOS", () => { ...@@ -124,6 +128,7 @@ describe("NotificationsIOS", () => {
nativeCancelLocalNotification = null; nativeCancelLocalNotification = null;
nativeCancelAllLocalNotifications = null; nativeCancelAllLocalNotifications = null;
nativeIsRegisteredForRemoteNotifications = null; nativeIsRegisteredForRemoteNotifications = null;
nativeCheckPermissions = null;
NotificationsIOS = null; NotificationsIOS = null;
NotificationAction = null; NotificationAction = null;
...@@ -309,4 +314,12 @@ describe("NotificationsIOS", () => { ...@@ -309,4 +314,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