xcode adsIdentifier 和 identifierForVendor 返回“00000000-0000-0000-0000-000000000000”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12605257/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The advertisingIdentifier and identifierForVendor return "00000000-0000-0000-0000-000000000000"
提问by J. Costa
I've implemented this methods to get advertisingIdentifier
and identifierForVendor
:
我已经实现了这个方法来获取advertisingIdentifier
和identifierForVendor
:
- (NSString *) advertisingIdentifier
{
if (!NSClassFromString(@"ASIdentifierManager")) {
return [OpenUDID value];
}
return [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
}
- (NSString *) identifierForVendor
{
if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
}
return @"";
}
- (BOOL)isAdvertisingTrackingEnabled
{
if (NSClassFromString(@"ASIdentifierManager") && ![[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]) {
return NO;
}
return YES;
}
On simulator everything is working as should be and I can get the 2 strings IDs representation.
在模拟器上一切正常,我可以获得 2 个字符串 ID 表示。
Butwhen I run from iPhone 3GS with iOS 6.0 (10A403), these 2 methods return "00000000-0000-0000-0000-000000000000" as identifier. Already done:
但是当我从带有 iOS 6.0 (10A403) 的 iPhone 3GS 运行时,这两种方法返回“00000000-0000-0000-0000-000000000000”作为标识符。已经完成了:
- Restarted the device
- Removed the app and reinstalled
- Created and Ad-Hoc build, installed, removed and installed again
- Run this code from another app
- Tested on iPad 2 with iOS 6.0 (10A403) and everything went ok (I've got the correct identifiers)
- 重启了设备
- 删除了应用程序并重新安装
- 创建和临时构建、安装、删除和再次安装
- 从另一个应用程序运行此代码
- 在带有 iOS 6.0 (10A403) 的 iPad 2 上测试,一切正常(我得到了正确的标识符)
采纳答案by MattP
It appears to be a bug in iOS. Seeing the same issue on devices that have been upgraded over-the-air, but devices upgraded with Xcode or iTunes work as expected without zeros.
这似乎是iOS中的一个错误。在通过无线方式升级的设备上看到同样的问题,但使用 Xcode 或 iTunes 升级的设备按预期工作,没有零。
Tried similar steps as you, and the only common theme was over-the-air (bad) versus tethered upgrade (good).
尝试了与您类似的步骤,唯一的共同主题是无线升级(坏)与系留升级(好)。
Update:Users that move directly from iOS 5.1 to 6.1 over-the-air experience a different behavior. Every time the app is closed completely and restarted, a new value is being returned by identifierForVendor
. This would be expected if the app was being uninstalled and reinstalled, but that's not the case.
更新:直接从 iOS 5.1 无线升级到 6.1 的用户体验不同的行为。每次应用程序完全关闭并重新启动时,都会返回一个新值identifierForVendor
。如果应用程序被卸载并重新安装,这是意料之中的,但事实并非如此。
回答by Peter B. Kramer
Apple confirmed this bug in their system in response to a Technical Support Incident request. They said that identifierForVendor
and advertisingIdentifier
sometimes
returning all zeros can be seen both in development builds and apps downloaded over the air from the App Store. They have no work around and can't say when the problem will be fixed.
Apple 应技术支持事件请求确认了其系统中的此错误。他们说,identifierForVendor
和advertisingIdentifier
有时返回所有零可以看出无论是在开发版本和应用程序下载量超过空气从App Store。他们没有解决办法,也不能说问题何时得到解决。
回答by vedrano
There are some situations where API returns empty response for ID like after device restore.
在某些情况下,API 会在设备恢复后为 ID 返回空响应。
Suggestion is to postpone ID retreival, so you can call sometginh like this:
建议是推迟 ID retreival,所以你可以像这样调用 sometginh:
-(void)retrieveID
{
if (<check fails>)
[self performSelector:@"retrieveID" withObject:nil afterDelay:1.0];
}
And fetch ID later.
并稍后获取ID。