iOS 7中蘋果再一次無情的封殺mac地址,現在已經不能獲取ios7設備的物理地址。那么在開發中如何才能標識設備的唯一性呢?apple公司提供的方法是通過keychain來存一些標志信息,然后通過存的標志信息來讓應用程序來識別該設備的唯一性。
apple公司寫了一個簡單的操作keychain的工具類:https://developer.apple.com/library/ios/samplecode/GenericKeychain/Listings/Classes_KeychainItemWrapper_m.html可以下載,把KeychainItemWrapper.h,.m文件引用xcode中,keychainItemWrapper.m文件可能出錯,這里是由于arc編譯造成的,我們可以根據提示進行解決,也可以用如下圖的方式解決:
接著設置keychain共享:如圖所示
此我們可以在項目中看到xxxxx.entitlements結尾的文件。<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/ <plist version="1.0"> <string>$(AppIdentifierPrefix)h.HelloWorld</string> </plist> 其中的${AppldentifierPrefix}是開發者賬戶的的前綴,是apple的公司提供的,https://developer.apple.com/membercenter/index.action,可以用自已的賬戶進行查看。 存取:key chain: 應用程序第一次在某臺設備上運行時,我們的應用程序保存一個uuid,來標識該設備。等設備把程序刪除時,該uuid依然存在于設備中。 -(void) setKeyChainValue{ KeychainItemWrapper *keyChainItem=[[KeychainItemWrapper alloc]initWithIdentifier:@"TestUUID" accessGroup:@"XXXXXX.h.HelloWorld"]; NSString *strUUID = [keyChainItem objectForKey:(id)kSecValueData]; if (strUUID==nil||[strUUID isEqualToString:@""]) { [keyChainItem setObject:[self gen_uuid] forKey:(id)kSecValueData]; } [keyChainItem release];}-(NSString *) gen_uuid{ CFUUIDRef uuid_ref=CFUUIDCreate(nil); CFStringRef uuid_string_ref=CFUUIDCreateString(nil, uuid_ref); CFRelease(uuid_ref); NSString *uuid=[NSString stringWithString:uuid_string_ref]; CFRelease(uuid_string_ref); return uuid;}
新聞熱點
疑難解答