简体   繁体   English

推送通知设备令牌?

[英]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. 此方法将在调试模式下在控制台中打印deviceToken,如果您想查看UIAlert中也可以看到的设备令牌。

- (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 这可能会发现它很有用http://urbanairship.com/docs/push.html

you can also look at Push Notification in Iphone application 您还可以在Iphone应用程序中查看推送通知

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);

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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