获取设备唯一标识
IOS
获取UUID,KeychainAccess中保存的keychain-access-groups为根证书id
const char * Utils::getDeviceId()
{
NSBundle *baudel = [NSBundle mainBundle];
NSString * kcaPath =[baudel pathForResource:@"KeychainAccess" ofType:@"plist"];
NSDictionary * kcad = [NSDictionary dictionaryWithContentsOfFile:kcaPath];
NSArray* kag = [kcad objectForKey:@"keychain-access-groups"];
NSString* kca = [kag objectAtIndex:0];
KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"UUID" accessGroup:kca];
NSString *struuid = [wrapper objectForKey:(id)kSecValueData];
if (struuid == nil || [struuid isEqualToString:@""])
{
CFUUIDRef pUUID = CFUUIDCreate(nil);
CFStringRef uuidStr = CFUUIDCreateString(nil, pUUID);
NSString *result = (NSString*)CFStringCreateCopy(NULL, uuidStr);
[wrapper setObject:result forKey:(id)kSecValueData];
}
struuid = [wrapper objectForKey:(id)kSecValueData];
[wrapper release];
return [struuid UTF8String];
}
其中KeychainAccess.plist为
<?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">
<dict>
<key>get-task-allow</key>
<false/>
<key>keychain-access-groups</key>
<array>
<string>xxxxxxxxx.xxx</string>
</array>
</dict>
</plist>
替换xxxxxxxxx.xxx为证书。
安卓
获取android_id
import android.provider.Settings;
String ANDROID_ID = Settings.System.getString(getContentResolver(), Settings.System.ANDROID_ID);
在部分越狱,返厂,以及安卓2.2上可能有问题