Get Device Token in iOS 8

前端 未结 8 2287
借酒劲吻你
借酒劲吻你 2020-12-05 05:12

I need device token to implement push notification in my app.
How can I get device token since didRegisterForRemoteNotificationsWithDeviceToken method is no

8条回答
  •  情书的邮戳
    2020-12-05 06:09

    Here is the solution.

    in applicationDidFinishLaunchingWithOptions:

    {
    
     UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
        UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
    }
    
    
    - (void)application:(UIApplication*)application didRegisterUserNotificationSettings:(nonnull UIUserNotificationSettings *)notificationSettings
    {
        [application registerForRemoteNotifications];
    }
    
    
    - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(nonnull NSError *)error
    {
        NSLog(@" Error while registering for remote notifications: %@", error);
    }
    
    - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(nonnull NSData *)deviceToken
    {
      NSLog(@"Device Token is : %@", deviceToken);
    }
    

提交回复
热议问题