ios - 另一个应用程序中的设备 token 更改

标签 ios objective-c iphone device devicetoken

我编写了 3 个应用程序来获取 iPad 中的设备 token ,但每个应用程序都有不同的设备 token 。

app1:4e8eb1d864c80fd8426615cd8ca4133c8bde78c30910cd1a8b82c917b612f38d
app2:2645100209412c457e87744c0af9ff323e28f6b2195c0fa9b835ddeebfe1391b
app3:f5958b3bad17feda02e64f9814f01cfafdda0b8283977214916c3d7eaa8b8dc8

这正常吗?我查过一些信息,说同一设备上的不同应用程序将获得相同的设备 token ...但根据我的测试,这似乎不正确。

如有任何评论,我们将不胜感激:)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
{
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeNewsstandContentAvailability];
}

return YES;

}

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

NSString *newToken =[deviceToken description];
newToken = [newToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
newToken = [newToken stringByReplacingOccurrencesOfString:@" " withString:@""];

NSLog(@"*******************");
NSLog(@"Token%@",newToken);}

-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
NSLog(@"errorwwwwww:%@",[error description]);}

最佳答案

这很正常!

设备 token 同时标识设备应用。想想看,这是完全有道理的,因为设备 token 用于在收到推送通知时识别 iOS 中的应用程序。如果每个应用程序都会返回设备 token ,那么一旦推送通知到达设备,iOS 将不知道将其发送到哪里。

关于ios - 另一个应用程序中的设备 token 更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28339109/

相关文章:

ios - child 失去了对 parent 的弱引用

ios - 如何在广播上传扩展(iOS)中实现上传?

iphone - 在设备锁定时播放 iPod 库中的音频

iOS:通过按 UIButton 更改 UIImageView

ios - 通过Instagram API发布时出现APINotAllowedError

android - GCM for iOS 和 Apple 提供的推送通知服务有什么区别

ios - PINRemoteImage 删除缓存

ios - 如果操作未完成,iPhone 应用程序会因dispatch_async 崩溃

iphone - 动画 :NO 时 pushViewController 不工作

iphone - ARC 中 CFArray 的内存泄漏