diff --git a/RNNotifications/RNNotifications.m b/RNNotifications/RNNotifications.m index e91494d2270f450f417cc010e9026ff7fa740305..e10edd11a914688b37dd32447f7db21d27737561 100644 --- a/RNNotifications/RNNotifications.m +++ b/RNNotifications/RNNotifications.m @@ -549,4 +549,17 @@ RCT_EXPORT_METHOD(cancelAllLocalNotifications) [RCTSharedApplication() cancelAllLocalNotifications]; } +RCT_EXPORT_METHOD(isRegisteredForRemoteNotifications:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) +{ + BOOL ans; + + if (TARGET_IPHONE_SIMULATOR) { + ans = [[[UIApplication sharedApplication] currentUserNotificationSettings] types] != 0; + } + else { + ans = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications]; + } + resolve(@(ans)); +} + @end diff --git a/index.ios.js b/index.ios.js index cce7a58f3dd724b303b2064d5e354cffeeadc216..fa7c06cf16d46f503767ebe19826e5a07c7fa7a8 100644 --- a/index.ios.js +++ b/index.ios.js @@ -203,4 +203,8 @@ export default class NotificationsIOS { static cancelAllLocalNotifications() { NativeRNNotifications.cancelAllLocalNotifications(); } + + static isRegisteredForRemoteNotifications() { + return NativeRNNotifications.isRegisteredForRemoteNotifications(); + } } diff --git a/test/index.ios.spec.js b/test/index.ios.spec.js index eb043d80c27bc9f05c5840f9c8ba1fb20b49888f..fd911bf2cca9c468cb7403200e2fe8faea832733 100644 --- a/test/index.ios.spec.js +++ b/test/index.ios.spec.js @@ -17,18 +17,19 @@ describe("NotificationsIOS", () => { /*eslint-disable indent*/ let deviceAddEventListener, - deviceRemoveEventListener, - nativeAppAddEventListener, - nativeAppRemoveEventListener, - nativeRequestPermissionsWithCategories, - nativeAbandonPermissions, - nativeRegisterPushKit, - nativeBackgroundTimeRemaining, - nativeConsumeBackgroundQueue, - nativeLocalNotification, - nativeCancelLocalNotification, - nativeCancelAllLocalNotifications, - nativeSetBadgesCount; + deviceRemoveEventListener, + nativeAppAddEventListener, + nativeAppRemoveEventListener, + nativeRequestPermissionsWithCategories, + nativeAbandonPermissions, + nativeRegisterPushKit, + nativeBackgroundTimeRemaining, + nativeConsumeBackgroundQueue, + nativeLocalNotification, + nativeCancelLocalNotification, + nativeCancelAllLocalNotifications, + nativeSetBadgesCount, + nativeIsRegisteredForRemoteNotifications; let NotificationsIOS, NotificationAction, NotificationCategory; let someHandler = () => {}; @@ -49,6 +50,7 @@ describe("NotificationsIOS", () => { nativeCancelLocalNotification = sinon.spy(); nativeCancelAllLocalNotifications = sinon.spy(); nativeSetBadgesCount = sinon.spy(); + nativeIsRegisteredForRemoteNotifications = sinon.spy(); let libUnderTest = proxyquire("../index.ios", { "uuid": { @@ -65,7 +67,8 @@ describe("NotificationsIOS", () => { localNotification: nativeLocalNotification, cancelLocalNotification: nativeCancelLocalNotification, cancelAllLocalNotifications: nativeCancelAllLocalNotifications, - setBadgesCount: nativeSetBadgesCount + setBadgesCount: nativeSetBadgesCount, + isRegisteredForRemoteNotifications: nativeIsRegisteredForRemoteNotifications } }, NativeAppEventEmitter: { @@ -104,6 +107,7 @@ describe("NotificationsIOS", () => { nativeLocalNotification.reset(); nativeCancelLocalNotification.reset(); nativeCancelAllLocalNotifications.reset(); + nativeIsRegisteredForRemoteNotifications.reset(); }); after(() => { @@ -119,6 +123,7 @@ describe("NotificationsIOS", () => { nativeLocalNotification = null; nativeCancelLocalNotification = null; nativeCancelAllLocalNotifications = null; + nativeIsRegisteredForRemoteNotifications = null; NotificationsIOS = null; NotificationAction = null; @@ -295,4 +300,13 @@ describe("NotificationsIOS", () => { expect(nativeCancelAllLocalNotifications).to.have.been.calledWith(); }); }); + + + describe("Is registered for remote notifications ", () => { + it("should call native is registered for remote notifications", () => { + NotificationsIOS.isRegisteredForRemoteNotifications(); + expect(nativeIsRegisteredForRemoteNotifications).to.have.been.calledWith(); + + }); + }); });