繁体   English   中英

推送通知设备令牌?

[英]Push Notification Device Token?

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

此方法将在调试模式下在控制台中打印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];

}

如果您已实现此方法

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

}

对于推送通知,您将获得设备令牌(此方法实际上是您在应用程序中实现的两种方法之一)

这可能会发现它很有用http://urbanairship.com/docs/push.html

您还可以在Iphone应用程序中查看推送通知

希望这个对你有帮助。

此方法将在控制台中显示您的设备令牌。

- (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