簡體   English   中英

[UIDevice currentDevice]可以使用什么?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM