0

So I have push notifications setup in my app and it works great. I've recently just learned about silent notifications and wanted to implement it in case a user opts out of push notifications. I've followed all the sources I can find, but I can't seem to get the device token. I'm not sure if I'm missing something.

In testing I'll decline the alert for push notications after this method is called:

- (void)registerForRemoteNotifications {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
    if(!error){
            dispatch_async(dispatch_get_main_queue(), ^{
                [[UIApplication sharedApplication] registerForRemoteNotifications];
            });
    }
}];

}

unlike when a user accepts push notifications:

didRegisterForRemoteNotificationsWithDeviceToken

is never called -- so I don't receive the current device token and I'm not able to update my server.

I've added background modes -> remote notifications and have also added the key/value in my plist.

Am I missing something? Thanks in advance for your help

Shivam Tripathi
  • 1,405
  • 3
  • 19
  • 37
tomrondo
  • 21
  • 1
  • 5

1 Answers1

0

Not sure why, but I ended up have to also check "background fetch" under background modes. I haven't seen this mentioned anywhere else, but I noticed background refresh wasn't showing up under settings for my app. Once I got that checked it works fine.

tomrondo
  • 21
  • 1
  • 5