-
Notifications
You must be signed in to change notification settings - Fork 504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove PushKit #3268
Remove PushKit #3268
Changes from 1 commit
53bb87d
a3890c6
7335682
9475cd7
f85aee0
87e702a
23203af
db01577
4e25323
09353f4
f25e3b6
7f39581
63d4a16
db8b5a4
ba50f47
b1a654d
69d9b5b
c4bdf33
fa44dae
a0e9540
f5324ae
3bd9e6b
bcd9683
d859ce8
845363b
4ef5e17
0b639e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ @interface PushNotificationService() | |
NSMutableDictionary <NSNumber *, MXOnNotification> *notificationListenerBlocks; | ||
} | ||
|
||
@property (nonatomic, strong) PKPushRegistry *pushRegistry; | ||
//@property (nonatomic, strong) PKPushRegistry *pushRegistry; | ||
|
||
@property (nonatomic) NSMutableDictionary <NSNumber *, NSMutableArray <NSString *> *> *incomingPushEventIds; | ||
|
||
|
@@ -110,16 +110,83 @@ - (void)registerUserNotificationSettings | |
|
||
- (void)registerForRemoteNotificationsWithCompletion:(nullable void (^)(NSError *))completion | ||
{ | ||
self.pushRegistry = [[PKPushRegistry alloc] initWithQueue:nil]; | ||
self.pushRegistry.delegate = self; | ||
self.pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP]; | ||
|
||
self.registrationForRemoteNotificationsCompletion = completion; | ||
|
||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
[[UIApplication sharedApplication] registerForRemoteNotifications]; | ||
}); | ||
} | ||
|
||
- (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken | ||
{ | ||
MXKAccountManager* accountManager = [MXKAccountManager sharedManager]; | ||
[accountManager setApnsDeviceToken:deviceToken]; | ||
// remove PushKit pusher if exists | ||
if (accountManager.pushDeviceToken) | ||
{ | ||
[accountManager setPushDeviceToken:nil withPushOptions:nil]; | ||
} | ||
// Sanity check: Make sure the Pushkit push token is deleted | ||
NSParameterAssert(!accountManager.isPushAvailable); | ||
NSParameterAssert(!accountManager.pushDeviceToken); | ||
|
||
_isPushRegistered = YES; | ||
|
||
if (self.registrationForRemoteNotificationsCompletion) | ||
{ | ||
self.registrationForRemoteNotificationsCompletion(nil); | ||
self.registrationForRemoteNotificationsCompletion = nil; | ||
} | ||
} | ||
|
||
- (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error | ||
{ | ||
[self clearPushNotificationToken]; | ||
|
||
if (self.registrationForRemoteNotificationsCompletion) | ||
{ | ||
self.registrationForRemoteNotificationsCompletion(error); | ||
self.registrationForRemoteNotificationsCompletion = nil; | ||
} | ||
} | ||
|
||
- (void)didReceiveRemoteNotification:(NSDictionary *)userInfo | ||
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler | ||
{ | ||
// NSLog(@"[PushNotificationService][Push] didReceiveRemoteNotification: applicationState: %tu - payload: %@", [UIApplication sharedApplication].applicationState, userInfo); | ||
// | ||
// // Display local notifications only when the app is running in background. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we remove commented code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
// if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) | ||
// { | ||
// NSLog(@"[PushNotificationService][Push] didReceiveRemoteNotification while app is in background"); | ||
// | ||
// // Check whether an event id is provided. | ||
// NSString *eventId = userInfo[@"event_id"]; | ||
// if (eventId) | ||
// { | ||
// // Add this event identifier in the pending push array for each session. | ||
// for (NSMutableArray *array in self.incomingPushEventIds.allValues) | ||
// { | ||
// [array addObject:eventId]; | ||
// } | ||
// | ||
// // Cache payload for further usage | ||
// incomingPushPayloads[eventId] = userInfo; | ||
// } | ||
// else | ||
// { | ||
// NSLog(@"[PushNotificationService][Push] didReceiveRemoteNotification - Unexpected payload %@", userInfo); | ||
// } | ||
// | ||
// // Trigger a background sync to handle notifications. | ||
// [self launchBackgroundSync]; | ||
// } | ||
// | ||
completionHandler(UIBackgroundFetchResultNewData); | ||
} | ||
|
||
- (void)deregisterRemoteNotifications | ||
{ | ||
self.pushRegistry = nil; | ||
_isPushRegistered = NO; | ||
} | ||
|
||
|
@@ -259,64 +326,64 @@ - (void)handleSessionStateChangesInBackgroundFor:(MXSession *)mxSession | |
} | ||
} | ||
|
||
#pragma mark - PKPushRegistryDelegate | ||
|
||
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(PKPushType)type | ||
{ | ||
NSData *token = credentials.token; | ||
|
||
NSLog(@"[PushNotificationService][Push] didUpdatePushCredentials: Got Push token: %@. Type: %@", [MXKTools logForPushToken:token], type); | ||
|
||
MXKAccountManager* accountManager = [MXKAccountManager sharedManager]; | ||
[accountManager setPushDeviceToken:token withPushOptions:@{@"format": @"event_id_only"}]; | ||
|
||
_isPushRegistered = YES; | ||
|
||
if (self.registrationForRemoteNotificationsCompletion) | ||
{ | ||
self.registrationForRemoteNotificationsCompletion(nil); | ||
self.registrationForRemoteNotificationsCompletion = nil; | ||
} | ||
} | ||
|
||
- (void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(PKPushType)type | ||
{ | ||
NSLog(@"[PushNotificationService][Push] didInvalidatePushTokenForType: Type: %@", type); | ||
|
||
[self clearPushNotificationToken]; | ||
} | ||
|
||
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type | ||
{ | ||
NSLog(@"[PushNotificationService][Push] didReceiveIncomingPushWithPayload: applicationState: %tu - type: %@ - payload: %@", [UIApplication sharedApplication].applicationState, payload.type, payload.dictionaryPayload); | ||
|
||
// Display local notifications only when the app is running in background. | ||
if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) | ||
{ | ||
NSLog(@"[PushNotificationService][Push] didReceiveIncomingPushWithPayload while app is in background"); | ||
|
||
// Check whether an event id is provided. | ||
NSString *eventId = payload.dictionaryPayload[@"event_id"]; | ||
if (eventId) | ||
{ | ||
// Add this event identifier in the pending push array for each session. | ||
for (NSMutableArray *array in self.incomingPushEventIds.allValues) | ||
{ | ||
[array addObject:eventId]; | ||
} | ||
|
||
// Cache payload for further usage | ||
incomingPushPayloads[eventId] = payload.dictionaryPayload; | ||
} | ||
else | ||
{ | ||
NSLog(@"[PushNotificationService][Push] didReceiveIncomingPushWithPayload - Unexpected payload %@", payload.dictionaryPayload); | ||
} | ||
|
||
// Trigger a background sync to handle notifications. | ||
[self launchBackgroundSync]; | ||
} | ||
} | ||
//#pragma mark - PKPushRegistryDelegate | ||
// | ||
//- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(PKPushType)type | ||
//{ | ||
// NSData *token = credentials.token; | ||
// | ||
// NSLog(@"[PushNotificationService][Push] didUpdatePushCredentials: Got Push token: %@. Type: %@", [MXKTools logForPushToken:token], type); | ||
// | ||
// MXKAccountManager* accountManager = [MXKAccountManager sharedManager]; | ||
// [accountManager setPushDeviceToken:token withPushOptions:@{@"format": @"event_id_only"}]; | ||
// | ||
// _isPushRegistered = YES; | ||
// | ||
// if (self.registrationForRemoteNotificationsCompletion) | ||
// { | ||
// self.registrationForRemoteNotificationsCompletion(nil); | ||
// self.registrationForRemoteNotificationsCompletion = nil; | ||
// } | ||
//} | ||
// | ||
//- (void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(PKPushType)type | ||
//{ | ||
// NSLog(@"[PushNotificationService][Push] didInvalidatePushTokenForType: Type: %@", type); | ||
// | ||
// [self clearPushNotificationToken]; | ||
//} | ||
|
||
//- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type | ||
//{ | ||
// NSLog(@"[PushNotificationService][Push] didReceiveIncomingPushWithPayload: applicationState: %tu - type: %@ - payload: %@", [UIApplication sharedApplication].applicationState, payload.type, payload.dictionaryPayload); | ||
// | ||
// // Display local notifications only when the app is running in background. | ||
// if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) | ||
// { | ||
// NSLog(@"[PushNotificationService][Push] didReceiveIncomingPushWithPayload while app is in background"); | ||
// | ||
// // Check whether an event id is provided. | ||
// NSString *eventId = payload.dictionaryPayload[@"event_id"]; | ||
// if (eventId) | ||
// { | ||
// // Add this event identifier in the pending push array for each session. | ||
// for (NSMutableArray *array in self.incomingPushEventIds.allValues) | ||
// { | ||
// [array addObject:eventId]; | ||
// } | ||
// | ||
// // Cache payload for further usage | ||
// incomingPushPayloads[eventId] = payload.dictionaryPayload; | ||
// } | ||
// else | ||
// { | ||
// NSLog(@"[PushNotificationService][Push] didReceiveIncomingPushWithPayload - Unexpected payload %@", payload.dictionaryPayload); | ||
// } | ||
// | ||
// // Trigger a background sync to handle notifications. | ||
// [self launchBackgroundSync]; | ||
// } | ||
//} | ||
|
||
#pragma mark - UNUserNotificationCenterDelegate | ||
|
||
|
@@ -374,12 +441,13 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNoti | |
} | ||
|
||
// iOS 10+, this is called when a notification is about to display in foreground. | ||
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler | ||
{ | ||
NSLog(@"[PushNotificationService][Push] willPresentNotification: applicationState: %@", @([UIApplication sharedApplication].applicationState)); | ||
|
||
completionHandler(UNNotificationPresentationOptionNone); | ||
} | ||
//- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler | ||
//{ | ||
// NSLog(@"[PushNotificationService][Push] willPresentNotification: applicationState: %@", @([UIApplication sharedApplication].applicationState)); | ||
// | ||
//// completionHandler(UNNotificationPresentationOptionNone); | ||
// completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert); | ||
//} | ||
|
||
#pragma mark - Other Methods | ||
|
||
|
@@ -607,7 +675,7 @@ - (NSDictionary*)notificationUserInfoForEvent:(MXEvent*)event andUserId:(NSStrin | |
} | ||
|
||
// iOS 10+, does the same thing as notificationBodyForEvent:pushRule:inAccount:onComplete:, except with more features | ||
- (void)notificationContentForEvent:(MXEvent *)event pushRule:(MXPushRule *)rule inAccount:(MXKAccount *)account onComplete:(void (^)(UNNotificationContent * _Nullable notificationContent))onComplete; | ||
- (void)notificationContentForEvent:(MXEvent *)event pushRule:(MXPushRule *)rule inAccount:(MXKAccount *)account onComplete:(void (^)(UNNotificationContent * _Nullable notificationContent))onComplete | ||
{ | ||
if (!event.content || !event.content.count) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we still log the call of this function?
It could be useful for sanity check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍