[iOS]iOS8可用的識別使用者方式(idfa、UUID、idfv)

來源:互聯網
上載者:User

[iOS]iOS8可用的識別使用者方式(idfa、UUID、idfv)

 

想要追蹤、統計使用者,自然離不開使用者唯一識別碼,這是每個公司都面臨的問題。在曆史上唯一識別碼很多,如UDID、MAC地址、OpenUDID等,不再一一介紹他們是怎麼掛掉的,現在好用的只剩下了idfa、idfv、UUID+keyChain。

 

idfa(Advertising Identifier):可以理解為廣告id,apple公司提供的用於追蹤使用者的廣告標識符。

缺點:使用者可通過設定-隱私-廣告-還原廣告標識符 還原,之後會得新的到標識符;

要求iOS>=6.0。

使用:

  #import   NSString *idfa= [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];


idfv (identifierForVendor):apple提供給Vendor的唯一識別碼,Vendor代表了應用開發商,實際使用時,一個Vendor是CFBundleIdentifier(反轉DNS格式)的前兩部分。例如,com.baidu.tieba 和 com.baidu.image 得到的idfv是相同的,因為它們的CFBundleIdentifier 前兩部分是相同的。

缺點:把同一個開發商的所有應用卸載後,再次安裝取到的idfv會不同。假設手機上裝有公司的兩款app:貼吧、

要求:iOS>=6.0

使用:

 NSString *idfv = [[[UIDevice currentDevice] identifierForVendor] UUIDString];

 

UUID(Universally Unique Identifier):通用唯一識別碼,每次產生均不一樣,所以第一次產生後需要儲存到鑰匙串,這樣即使應用刪除再重裝仍然可以從鑰匙串得到它。

使用:

UUID產生方法很多種,這裡唯寫出一種。產生一個UUID:

 

-(NSString*) uuid {    CFUUIDRef puuid = CFUUIDCreate( nil );    CFStringRef uuidString = CFUUIDCreateString( nil, puuid );    NSString * result = (NSString *)CFBridgingRelease(CFStringCreateCopy( NULL, uuidString));    CFRelease(puuid);    CFRelease(uuidString);    return result;}
將UUID儲存在鑰匙串,這裡用到了一個第三方的工具 SFHFKeychainUtils,github地址

 

 

 [SFHFKeychainUtils storeUsername:@UDID andPassword:[self uuid] forServiceName:@ZYB updateExisting:1 error:nil];
從鑰匙串取出UUID:

 

 

[SFHFKeychainUtils getPasswordForUsername:@UDID andServiceName:@ZYB error:nil]

注意,如果沒有儲存就直接取出會crash。

 

 

相關文章

聯繫我們

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