本來可以用下面的代碼輕鬆獲取UDID號:
NSString *uuid = [[UIDevice currentDevice] uniqueIdentifier];
不過iOS5後, uniqueIdentifier 這個函數被廢除了, 編譯不過去。
只能另外想辦法。
網上找了一下, 有可以替代的方案,這個方案還是比較靠譜的。
該解決方案源碼地址:
https://github.com/gekitz/UIDevice-with-UniqueIdentifier-for-iOS-5
該方案提供了兩個方法:
uniqueDeviceIdentifier (返回MAC和CFBundleIdentifier的MD5值)
uniqueGlobalDeviceIdentifier(返回MAC的MD5值)
使用方法:
#import "UIDevice+IdentifierAddition.h"
NSLog(@"%@",[[UIDevice currentDevice] uniqueDeviceIdentifier]);
NSLog(@"%@",[[UIDevice currentDevice] uniqueGlobalDeviceIdentifier]);
還有就是OpenUDID開源庫的方案, 不過這個方案我下載後, 在我的IOS7上編譯不過去, 最後沒有使用。
OpenUDID下載地址:https://github.com/ylechelle/OpenUDID
還有一個方案叫 SecureUDID, 沒有使用過。
SecureUDID下載地址:https://github.com/crashlytics/secureudid