From b02b4eb548482db6767a9a08de741e69d183a530 Mon Sep 17 00:00:00 2001 From: Nicolas Lourenco Date: Tue, 9 Apr 2019 17:57:33 -0700 Subject: [PATCH] Fix the notification registration --- .../GraphNotificationsSample/AppDelegate.m | 16 +-------------- .../ConnectedDevicesPlatformManager.h | 2 +- .../ConnectedDevicesPlatformManager.m | 20 +++++++++---------- 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/iOS/samples/GraphNotifications/GraphNotificationsSample/AppDelegate.m b/iOS/samples/GraphNotifications/GraphNotificationsSample/AppDelegate.m index bdf6c66..95b196c 100644 --- a/iOS/samples/GraphNotifications/GraphNotificationsSample/AppDelegate.m +++ b/iOS/samples/GraphNotifications/GraphNotificationsSample/AppDelegate.m @@ -29,20 +29,6 @@ - (void)initializePlatform } } - - -- (void)createNotificationRegistrationWithToken:(NSString* _Nonnull)deviceToken -{ - _notificationRegistration = [[MCDConnectedDevicesNotificationRegistration alloc] init]; - _notificationRegistration.type = MCDNotificationTypeAPN; - _notificationRegistration.appId = [[NSBundle mainBundle] bundleIdentifier]; - _notificationRegistration.appDisplayName = (NSString*)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]; - _notificationRegistration.token = deviceToken; - NSLog(@"GraphNotifications Successfully created notification registration!"); - NSLog(@"platformManager info %@", _platformManager); - [_platformManager setNotificationRegistration: _notificationRegistration]; -} - - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler); @@ -146,7 +132,7 @@ - (void)application:(__unused UIApplication*)application didRegisterForRemoteNot @try { - [self createNotificationRegistrationWithToken:deviceTokenStr]; + [_platformManager setNotificationRegistration: deviceTokenStr]; } @catch (NSException* exception) { diff --git a/iOS/samples/GraphNotifications/GraphNotificationsSample/ConnectedDevicesPlatformManager.h b/iOS/samples/GraphNotifications/GraphNotificationsSample/ConnectedDevicesPlatformManager.h index ac54732..df1d49e 100644 --- a/iOS/samples/GraphNotifications/GraphNotificationsSample/ConnectedDevicesPlatformManager.h +++ b/iOS/samples/GraphNotifications/GraphNotificationsSample/ConnectedDevicesPlatformManager.h @@ -60,7 +60,7 @@ typedef NS_ENUM(NSInteger, AccountRegistrationState) { - (AnyPromise*)signInMsaAsync; - (AnyPromise*)signOutAsync:(Account*)account; - (NSMutableArray*)deserializeAccounts; -- (void)setNotificationRegistration:(MCDConnectedDevicesNotificationRegistration*)registration; +- (void)setNotificationRegistration:(NSString*)deviceToken; @end #endif /* ConnectedDevicesPlatformManager_h */ diff --git a/iOS/samples/GraphNotifications/GraphNotificationsSample/ConnectedDevicesPlatformManager.m b/iOS/samples/GraphNotifications/GraphNotificationsSample/ConnectedDevicesPlatformManager.m index 3244cfa..bc66463 100644 --- a/iOS/samples/GraphNotifications/GraphNotificationsSample/ConnectedDevicesPlatformManager.m +++ b/iOS/samples/GraphNotifications/GraphNotificationsSample/ConnectedDevicesPlatformManager.m @@ -444,23 +444,24 @@ - (AnyPromise*)signOutAsync:(Account*)account { }); } -- (void)setNotificationRegistration:(NSString*)tokenString { +- (void)setNotificationRegistration:(NSString*)deviceToken { + MCDConnectedDevicesNotificationRegistration* notificationRegistration = [[MCDConnectedDevicesNotificationRegistration alloc] init]; + notificationRegistration.type = MCDNotificationTypeAPN; + notificationRegistration.appId = [[NSBundle mainBundle] bundleIdentifier]; + notificationRegistration.appDisplayName = (NSString*)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]; + notificationRegistration.token = deviceToken; - MCDConnectedDevicesNotificationRegistration* registration = [MCDConnectedDevicesNotificationRegistration new]; + NSLog(@"GraphNotifications Successfully created notification registration!"); if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) { - registration.type = MCDNotificationTypeAPN; + notificationRegistration.type = MCDNotificationTypeAPN; } else { - registration.type = MCDNotificationTypePolling; + notificationRegistration.type = MCDNotificationTypePolling; } - registration.appId = [[NSBundle mainBundle] bundleIdentifier]; - registration.appDisplayName = (NSString*)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]; - registration.token = tokenString; - // The two cases of receiving a new notification token are: // 1. A notification registration is asked for and now it is available. In this case there is a pending promise that was made // at the time of requesting the information. It now needs completed. @@ -468,8 +469,7 @@ - (void)setNotificationRegistration:(NSString*)tokenString { // // In order to most cleany handle both cases set the new notification information and then trigger a re registration of all accounts // that are in good standing. - [self.apnsManager setNotificationRegistration:registration accounts:self.accounts]; + [self.apnsManager setNotificationRegistration:notificationRegistration accounts:self.accounts]; } - @end