Skip to content
This repository was archived by the owner on Jul 28, 2022. It is now read-only.

Commit be2fc7b

Browse files
chdepsMinishlink
authored andcommitted
Support Inbox for iOS (#2)
* Add Batch push notification interface * Start implementing fetchNewNotifications on ios * Suppose date is already a timestamp * Fix timestamp * Add payload * timeIntervalSince1970 is a double * Update README * Use milliseconds for timestamp
1 parent b05d295 commit be2fc7b

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ BatchPush.logoutUser(); // when the user logs out
8484
```
8585

8686
### Inbox
87-
Only on Android at the moment. See the [Batch's docs](https://batch.com/doc/ios/inbox.html) if you want to do a PR!
88-
8987
```js
9088
import BatchPush from 'react-native-batch-push';
9189

ios/RNBatchPush.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,30 @@ - (id)init {
3939
[editor save];
4040
}
4141

42+
RCT_REMAP_METHOD(fetchNewNotifications,
43+
fetchNewNotificationsWithUserID:(NSString*)userID authKey:(NSString*)authKey resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
44+
{
45+
BatchInboxFetcher* inboxFetcher = [BatchInbox fetcherForUserIdentifier:userID authenticationKey:authKey];
46+
[inboxFetcher fetchNewNotifications:^(NSError * _Nullable error, NSArray<BatchInboxNotificationContent *> * _Nullable notifications, BOOL foundNewNotifications, BOOL endReached) {
47+
48+
if(error) {
49+
reject(@"BATCH_ERROR", @"Error fetching new notifications", error);
50+
return;
51+
}
52+
53+
NSMutableArray* jsNotifications = [[NSMutableArray alloc] init];
54+
55+
for (BatchInboxNotificationContent* notification in notifications) {
56+
NSMutableDictionary* jsNotification = [NSMutableDictionary new];
57+
[jsNotification setObject:notification.title forKey:@"title"];
58+
[jsNotification setObject:notification.body forKey:@"body"];
59+
[jsNotification setObject:@([notification.date timeIntervalSince1970] * 1000.0) forKey:@"timestamp"];
60+
[jsNotification setObject:notification.payload forKey:@"payload"];
61+
[jsNotifications addObject:jsNotification];
62+
}
63+
64+
resolve(jsNotifications);
65+
}];
66+
}
67+
4268
@end

0 commit comments

Comments
 (0)