APNS - Getting a device token

I am going to implement push notifications in my application using the AppNotify service. To finish the configuration of this service, I need to get the token of my device. I tried using code from Apple docs. On the simulator, I get an error message (expected, of course). I have no error on my device, but I am not getting a token either. Neither the delegate method is called. Here is the code (the first bit goes to applicationDidFinishLaunching):

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];



- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
//const void *devTokenBytes = [devToken bytes];
//self.registered = YES;
//[self sendProviderDeviceToken:devTokenBytes]; // custom method
NSLog(@"Success");
NSLog(@"Token = %@", devToken);
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
    NSLog(@"Error in registration. Error: %@", err);
}

Any ideas why this is happening?

thank

+3
source share
2 answers

Once you find out that remote notifications do not work on the simulator.

Hi

+2
source

add the following method:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{
       for (id key in userInfo)
       {
             NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
        }    
}

( ), (2, , , ). , ( 10 , ) didRegisterForRemoteNotificationsWithDeviceToken . .

+2

Source: https://habr.com/ru/post/1735730/


All Articles