Commit 4567efcb authored by Ran's avatar Ran Committed by GitHub

Merge pull request #87 from wix/isRegisteredForRemoteNotifications

iOS API - Is registered for remote notifications
parents 43a4c895 cb2ec057
...@@ -549,4 +549,17 @@ RCT_EXPORT_METHOD(cancelAllLocalNotifications) ...@@ -549,4 +549,17 @@ RCT_EXPORT_METHOD(cancelAllLocalNotifications)
[RCTSharedApplication() 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 @end
...@@ -203,4 +203,8 @@ export default class NotificationsIOS { ...@@ -203,4 +203,8 @@ export default class NotificationsIOS {
static cancelAllLocalNotifications() { static cancelAllLocalNotifications() {
NativeRNNotifications.cancelAllLocalNotifications(); NativeRNNotifications.cancelAllLocalNotifications();
} }
static isRegisteredForRemoteNotifications() {
return NativeRNNotifications.isRegisteredForRemoteNotifications();
}
} }
...@@ -28,7 +28,8 @@ describe("NotificationsIOS", () => { ...@@ -28,7 +28,8 @@ describe("NotificationsIOS", () => {
nativeLocalNotification, nativeLocalNotification,
nativeCancelLocalNotification, nativeCancelLocalNotification,
nativeCancelAllLocalNotifications, nativeCancelAllLocalNotifications,
nativeSetBadgesCount; nativeSetBadgesCount,
nativeIsRegisteredForRemoteNotifications;
let NotificationsIOS, NotificationAction, NotificationCategory; let NotificationsIOS, NotificationAction, NotificationCategory;
let someHandler = () => {}; let someHandler = () => {};
...@@ -49,6 +50,7 @@ describe("NotificationsIOS", () => { ...@@ -49,6 +50,7 @@ describe("NotificationsIOS", () => {
nativeCancelLocalNotification = sinon.spy(); nativeCancelLocalNotification = sinon.spy();
nativeCancelAllLocalNotifications = sinon.spy(); nativeCancelAllLocalNotifications = sinon.spy();
nativeSetBadgesCount = sinon.spy(); nativeSetBadgesCount = sinon.spy();
nativeIsRegisteredForRemoteNotifications = sinon.spy();
let libUnderTest = proxyquire("../index.ios", { let libUnderTest = proxyquire("../index.ios", {
"uuid": { "uuid": {
...@@ -65,7 +67,8 @@ describe("NotificationsIOS", () => { ...@@ -65,7 +67,8 @@ describe("NotificationsIOS", () => {
localNotification: nativeLocalNotification, localNotification: nativeLocalNotification,
cancelLocalNotification: nativeCancelLocalNotification, cancelLocalNotification: nativeCancelLocalNotification,
cancelAllLocalNotifications: nativeCancelAllLocalNotifications, cancelAllLocalNotifications: nativeCancelAllLocalNotifications,
setBadgesCount: nativeSetBadgesCount setBadgesCount: nativeSetBadgesCount,
isRegisteredForRemoteNotifications: nativeIsRegisteredForRemoteNotifications
} }
}, },
NativeAppEventEmitter: { NativeAppEventEmitter: {
...@@ -104,6 +107,7 @@ describe("NotificationsIOS", () => { ...@@ -104,6 +107,7 @@ describe("NotificationsIOS", () => {
nativeLocalNotification.reset(); nativeLocalNotification.reset();
nativeCancelLocalNotification.reset(); nativeCancelLocalNotification.reset();
nativeCancelAllLocalNotifications.reset(); nativeCancelAllLocalNotifications.reset();
nativeIsRegisteredForRemoteNotifications.reset();
}); });
after(() => { after(() => {
...@@ -119,6 +123,7 @@ describe("NotificationsIOS", () => { ...@@ -119,6 +123,7 @@ describe("NotificationsIOS", () => {
nativeLocalNotification = null; nativeLocalNotification = null;
nativeCancelLocalNotification = null; nativeCancelLocalNotification = null;
nativeCancelAllLocalNotifications = null; nativeCancelAllLocalNotifications = null;
nativeIsRegisteredForRemoteNotifications = null;
NotificationsIOS = null; NotificationsIOS = null;
NotificationAction = null; NotificationAction = null;
...@@ -295,4 +300,13 @@ describe("NotificationsIOS", () => { ...@@ -295,4 +300,13 @@ describe("NotificationsIOS", () => {
expect(nativeCancelAllLocalNotifications).to.have.been.calledWith(); 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();
});
});
}); });
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