简体   繁体   中英

Push Notification Device Token?

如何从我的iPhone设备获取设备令牌?

this method will print the deviceToken in console in debug mode, if you want to see the device token you can see in UIAlert also.

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSLog(@"APN device token: %@", deviceToken);
    NSString *deviceTokenString = [NSString stringWithFormat:@"%@",deviceToken];
    UIAlertView *deviceTokenAlert = [[UIAlertView alloc] initWithTitle:@"Device Token"
                                                            message:deviceTokenString
                                                           delegate:self
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];

}

If you have implemented this method

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

}

for Push Notification then you will get the device token (This method is actually one of the two methods that you require to implement in the application)

This might find it useful http://urbanairship.com/docs/push.html

you can also look at Push Notification in Iphone application

I hope you find this useful.

This method will show your device token in console.

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 

    NSString *str = [NSString 
                     stringWithFormat:@"%@",deviceToken];
    NSString *newString = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
    newString = [newString stringByReplacingOccurrencesOfString:@"<" withString:@""];
    newString = [newString stringByReplacingOccurrencesOfString:@">" withString:@""];


    [[NSUserDefaults standardUserDefaults] setObject:newString forKey:@"deviceToken"];



    NSLog(@"Your deviceToken ---> %@",newString);

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM