Skip to content

Commit 4567efc

Browse files
authored
Merge pull request wix#87 from wix/isRegisteredForRemoteNotifications
iOS API - Is registered for remote notifications
2 parents 43a4c89 + cb2ec05 commit 4567efc

File tree

3 files changed

+44
-13
lines changed

3 files changed

+44
-13
lines changed

RNNotifications/RNNotifications.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,4 +549,17 @@ - (void)handleNotificationActionTriggered:(NSNotification *)notification
549549
[RCTSharedApplication() cancelAllLocalNotifications];
550550
}
551551

552+
RCT_EXPORT_METHOD(isRegisteredForRemoteNotifications:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
553+
{
554+
BOOL ans;
555+
556+
if (TARGET_IPHONE_SIMULATOR) {
557+
ans = [[[UIApplication sharedApplication] currentUserNotificationSettings] types] != 0;
558+
}
559+
else {
560+
ans = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
561+
}
562+
resolve(@(ans));
563+
}
564+
552565
@end

index.ios.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,8 @@ export default class NotificationsIOS {
203203
static cancelAllLocalNotifications() {
204204
NativeRNNotifications.cancelAllLocalNotifications();
205205
}
206+
207+
static isRegisteredForRemoteNotifications() {
208+
return NativeRNNotifications.isRegisteredForRemoteNotifications();
209+
}
206210
}

test/index.ios.spec.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@ describe("NotificationsIOS", () => {
1717

1818
/*eslint-disable indent*/
1919
let deviceAddEventListener,
20-
deviceRemoveEventListener,
21-
nativeAppAddEventListener,
22-
nativeAppRemoveEventListener,
23-
nativeRequestPermissionsWithCategories,
24-
nativeAbandonPermissions,
25-
nativeRegisterPushKit,
26-
nativeBackgroundTimeRemaining,
27-
nativeConsumeBackgroundQueue,
28-
nativeLocalNotification,
29-
nativeCancelLocalNotification,
30-
nativeCancelAllLocalNotifications,
31-
nativeSetBadgesCount;
20+
deviceRemoveEventListener,
21+
nativeAppAddEventListener,
22+
nativeAppRemoveEventListener,
23+
nativeRequestPermissionsWithCategories,
24+
nativeAbandonPermissions,
25+
nativeRegisterPushKit,
26+
nativeBackgroundTimeRemaining,
27+
nativeConsumeBackgroundQueue,
28+
nativeLocalNotification,
29+
nativeCancelLocalNotification,
30+
nativeCancelAllLocalNotifications,
31+
nativeSetBadgesCount,
32+
nativeIsRegisteredForRemoteNotifications;
3233

3334
let NotificationsIOS, NotificationAction, NotificationCategory;
3435
let someHandler = () => {};
@@ -49,6 +50,7 @@ describe("NotificationsIOS", () => {
4950
nativeCancelLocalNotification = sinon.spy();
5051
nativeCancelAllLocalNotifications = sinon.spy();
5152
nativeSetBadgesCount = sinon.spy();
53+
nativeIsRegisteredForRemoteNotifications = sinon.spy();
5254

5355
let libUnderTest = proxyquire("../index.ios", {
5456
"uuid": {
@@ -65,7 +67,8 @@ describe("NotificationsIOS", () => {
6567
localNotification: nativeLocalNotification,
6668
cancelLocalNotification: nativeCancelLocalNotification,
6769
cancelAllLocalNotifications: nativeCancelAllLocalNotifications,
68-
setBadgesCount: nativeSetBadgesCount
70+
setBadgesCount: nativeSetBadgesCount,
71+
isRegisteredForRemoteNotifications: nativeIsRegisteredForRemoteNotifications
6972
}
7073
},
7174
NativeAppEventEmitter: {
@@ -104,6 +107,7 @@ describe("NotificationsIOS", () => {
104107
nativeLocalNotification.reset();
105108
nativeCancelLocalNotification.reset();
106109
nativeCancelAllLocalNotifications.reset();
110+
nativeIsRegisteredForRemoteNotifications.reset();
107111
});
108112

109113
after(() => {
@@ -119,6 +123,7 @@ describe("NotificationsIOS", () => {
119123
nativeLocalNotification = null;
120124
nativeCancelLocalNotification = null;
121125
nativeCancelAllLocalNotifications = null;
126+
nativeIsRegisteredForRemoteNotifications = null;
122127

123128
NotificationsIOS = null;
124129
NotificationAction = null;
@@ -295,4 +300,13 @@ describe("NotificationsIOS", () => {
295300
expect(nativeCancelAllLocalNotifications).to.have.been.calledWith();
296301
});
297302
});
303+
304+
305+
describe("Is registered for remote notifications ", () => {
306+
it("should call native is registered for remote notifications", () => {
307+
NotificationsIOS.isRegisteredForRemoteNotifications();
308+
expect(nativeIsRegisteredForRemoteNotifications).to.have.been.calledWith();
309+
310+
});
311+
});
298312
});

0 commit comments

Comments
 (0)