UUIDString的identifierForVendor返回null

Meh*_*nki 8 push-notification apple-push-notifications iphone-5 ios7

我在我的iPhone应用程序中实现了推送通知,并且我在应用程序中使用了以下代码进行设备注册.

[[[UIDevice currentDevice] identifierForVendor] UUIDString];
Run Code Online (Sandbox Code Playgroud)

上面的代码在大多数设备中运行良好.然而,最近在iOS 7.1的一些iPhone 5s设备中它返回null并且由于这个应用程序崩溃.

Mik*_*ike 5

根据Apple文档

如果值为nil,请稍后再次获取该值.例如,在设备重新启动之后但在用户解锁设备之前,会发生这种情况

你可以在这里阅读:UIDevice

我们的应用程序遇到了同样的问题,我们最终使用的是

[[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]
Run Code Online (Sandbox Code Playgroud)

这是它的参考:ASIdentifierManager

根据经验,在同一设备上重新安装时,标识符保持不变.我没有在它发生变化时发现模式,但它确实......与identifierForVendor相同.

  • Apple已明确禁止将广告标识符用于"实施广告系统"以外的任何其他内容. (6认同)

Nil*_*mar -3

由于这是一个老问题,我也面临着同样的问题。所以我觉得在这里为其他人回答,如果他们遇到这个问题。

NSString *uid=[[UIDevice currentDevice] uniqueIdentifier];
NSLog(@"udd:%@",uid);
Run Code Online (Sandbox Code Playgroud)