Tags: push push iOS8 Devicetoken token xcode6 Original: http://roybaby.blog.51cto.com/1508945/1557854
Open APPDELEGATE.M
What to do:
First of all:
| 12345678910111213 |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptionsadd Code like this#ifdef __IPHONE_8_0 //Right, that is the point UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert) categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings];#else //register to receive notifications UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound; [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];#endif |
Then:
Add the following function
| 12345678910111213141516 |
#ifdef __IPHONE_8_0- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings{ //register to receive notifications [application registerForRemoteNotifications];}- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler{ //handle the actions if([identifier isEqualToString:@"declineAction"]){ } elseif ([identifier isEqualToString:@"answerAction"]){ }}#endif |
Then you'll get devicetoken in the following ways
| 1 |
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken |
If the function is not responding, use the following function and NSLog error
| 1 |
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error |
"Go" iOS8 push get Devicetoken