[英]Alternative to [UIDevice currentDevice].identifierForVendor
[英]What can be used with [UIDevice currentDevice]?
[UIDevice currentDevice]
可以是什么,例如uniqueIdentifier? 謝謝!
因為這有點過時了,所以我現在給出一個最新的答案。
因為Apple
認為適合阻止開發人員使用[[UIDevice currentDevice] uniqueIdentifier];
從iOS 6
開始, Suhail Patels
回答要使用的建議。 他們現在已經開始告訴開發人員使用[[UIDevice currentDevice] identifierForVendor];
,但是即使他們仍在為iOS 5
和更低iOS 5
開發,一些開發人員對於是否仍然允許使用uniqueIdentifier
感到困惑。 Apple
對此一直有點挑剔:
"Apps that use the `UDID` will be rejected in the App Store review process.."
來吧Apple
給我們更多的細節。
無論如何,由於其背后的困惑,一些開發人員已開始使用OpenUDID來獲取唯一標識符。 以下是一些有關如何使用它的代碼:
if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
// Use: [[[UIDevice currentDevice] identifierForVendor] UUIDString];
} else {
// Use: [OpenUDID value];
}
編輯
由於不推薦使用UDID
因此一些開發人員現在也適合開始使用MAC地址。 這是因為MAC地址基於硬件,因此無法更改。 對於那些想要使用MAC地址方式的人,蘋果在“ 獲取MAC地址”中提供了一些示例代碼。
對於iOS 5,您可以使用以下命令創建一個新的但不是唯一的標識符:
CFUUIDRef UIID = CFUUIDCreate(NULL);
CFStringRef UIIDString = (CFUUIDCreateString(NULL, UIID));
NSString *string = [NSString stringWithFormat:@"%@",UIIDString];
將其保存在文件中並像唯一標識符一樣使用
與UIDevice對象關聯的所有屬性和方法在《 UIDevice類參考》中進行了描述。
要訪問唯一標識符,您可以執行以下操作:
NSString *identifier = [[UIDevice currentDevice] uniqueIdentifier];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.