標籤: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