Posts

Post marked as solved
4 Replies
6.4k Views
I'm looking for verification that this is correct, or to be corrected if this is wrong.Here's some code:#import <UserNotifications/UserNotifications.h>My AppDelegate.h has this:@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>And willFinishLaunchingWithOptions has this:UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){ if( !error ) { NSLog( @"Push registration success." ); } else { NSLog( @"Push registration FAILED." ); } }];I'm getting the success message. So far, so good.In previous iOS versions, this delegate method was called:- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceTokenFor iOS 10, I can get this method to be called if I add this to my requestAuthorizationWithOptions completionHandler:[[UIApplication sharedApplication] registerForRemoteNotifications];Is this the right way to do it? It seems incorrect because, when I do this, the old application:didReceiveRemoteNotification method is still firing, as-is the new center:didReceiveNotificationResponse.So, two things are firing now when a user taps a notification, and that does not seem right. However, if I remove the call to registerForRemoteNotifications, nothing fires when I receive a remote notification. And that makes sense because we have to have the device token to send to AWS, which facilitates delivery of notifications between us and Apple and Google.I don't see a way to get the device token from any of the new UserNotification classes, but it seems like I've done something wrong since UIApplicationDelegate and UNUserNotificationCenterDelegate are both reacting to push notifications.Any input?Thanks.
Posted
by costmosf.
Last updated
.