推送通知设备令牌?

发布于 2024-08-03 06:49:53 字数 29 浏览 2 评论 0原文

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

How to get Device Token from my iPhone Device?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

缘字诀 2024-08-10 06:49:53

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

}

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

}
梦里泪两行 2024-08-10 06:49:53

如果您已经

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

}

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

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

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

我希望您发现这很有用。

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.

秋心╮凉 2024-08-10 06:49:53

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

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

}

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

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文