iOS唯一碼

來源:互聯網
上載者:User

標籤:

  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/PropertyList-1.0.dtd">

<plist version="1.0">

<string>$(AppIdentifierPrefix)h.HelloWorld</string>

</plist>

其中的${AppldentifierPrefix}是開發人員賬戶的的首碼,是apple的公司提供的,https://developer.apple.com/membercenter/index.action,可以用自已的賬戶進行查看。

存取:key chain:

Java代碼  
  1. -(void) setKeyChainValue  
  2. {  
  3.     KeychainItemWrapper *keyChainItem=[[KeychainItemWrapper alloc]initWithIdentifier:@"TestUUID" accessGroup:@"XXXXXX.h.HelloWorld"];  
  4.     NSString *strUUID = [keyChainItem objectForKey:(id)kSecValueData];  
  5.     if (strUUID==nil||[strUUID isEqualToString:@""])  
  6.     {  
  7.         [keyChainItem setObject:[self gen_uuid] forKey:(id)kSecValueData];  
  8.     }  
  9.     [keyChainItem release];  
  10.   
  11. }  
  12.   
  13. -(NSString *) gen_uuid  
  14. {  
  15.     CFUUIDRef uuid_ref=CFUUIDCreate(nil);  
  16.     CFStringRef uuid_string_ref=CFUUIDCreateString(nil, uuid_ref);  
  17.     CFRelease(uuid_ref);  
  18.     NSString *uuid=[NSString stringWithString:uuid_string_ref];  
  19.     CFRelease(uuid_string_ref);  
  20.     return uuid;  
  21. }  

   應用程式第一次在某台裝置上運行時,我們的應用程式儲存一個uuid,來標識該裝置。等裝置把程式刪除時,該uuid依然存在於裝置中。

iOS唯一碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.