IOS UUID 擷取

來源:互聯網
上載者:User

標籤:style   blog   http   color   使用   os   io   檔案   

擷取裝置唯一ID.

現在IOS7的安裝覆蓋率已經超過80%了。IOS7不能使用擷取的UDID的介面(涉及到隱私),之前有不少人採用取得MAC地址的方式,IOS7下這個介面也廢棄了,現在可以的方式是用UUID,但是UUID一個不好的地方是每次調用一次,產生的就不一樣,這個會導致一旦APP卸載重裝,UUID就變了。

 

所以呢,在第一次使用的時候,建立產生一個UUID,然後把這個UUID和應用的ID一起儲存到keychain(個人理解應該和windows的註冊表類似)中,下次需要時,從keychain讀取,這樣就算APP卸載了,只要裝置沒進行reset,則UUID讀出來還是不變的。

 

#import "SSKeychain.h"

 void GetIOSUUID(string& sRetUUID)
 {
  NSString *retrieveuuid = [SSKeychain passwordForService:@"com.91.dhdar"account:@"uuid"];
  if ( retrieveuuid == nil || [retrieveuuid isEqualToString:@""])
  {
   CFUUIDRef uuid = CFUUIDCreate(NULL);
   assert(uuid != NULL);
   CFStringRef uuidStr = CFUUIDCreateString(NULL, uuid);
   retrieveuuid = [NSString stringWithFormat:@"%@", uuidStr];
   [SSKeychain setPassword: retrieveuuid
                forService:@"com.game.userinfo"account:@"uuid"];
  }
  if (retrieveuuid ~= nil)
  {
   sRetUUID = [retrieveuuid UTF8String];
  }
  else
  {
   sRetUUID = "null";
  }

 }

需要用到SSKeychain,從這裡下載

http://github.com/soffes/sskeychain

 

把SSKeychain 檔案夾拷進去

=============================================

參考:

http://blog.woodbunny.com/post-104.html

http://blog.csdn.net/wave_1102/article/details/11894133

http://www.cnblogs.com/howeho/p/3316573.html

https://developer.apple.com/library/ios/samplecode/GenericKeychain/Listings/Classes_KeychainItemWrapper_h.html#//apple_ref/doc/uid/DTS40007797-Classes_KeychainItemWrapper_h-DontLinkElementID_9


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.