"Go" iOS8 push get Devicetoken

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.