我搜索了一圈,发现目前木有最完美的替代方案了。
网上各种方案,最后我还是选择了MAC + (UUID+keychain),也就是两个方案结合起来用。MAC就不多说了,0X02:00:00:00:00:00已经固定为IOS7的地址了。所以这里做了一个双重选择。
首先声明,UUID+keychain,目前我是只用来做存档的。所以没有考虑特别的用途。
实现代码为:
- (NSString*) udidUsingCFUUID
{
// initialize keychaing item for saving UUID.
KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"UUID" accessGroup:nil];
NSString *uuid = [wrapper objectForKey:(id)kSecAttrAccount];
if( uuid == nil || uuid.length == 0)
{
// if there is not UUID in keychain, make UUID and save it.
CFUUIDRef uuidRef = CFUUIDCreate(NULL);
CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef);
CFRelease(uuidRef);
uuid = [NSString stringWithString:(NSString *) uuidStringRef];
CFRelease(uuidStringRef);
// save UUID in keychain
[wrapper setObject:uuid forKey:(id)kSecAttrAccount];
}
return uuid;
}
需要导入Security.framework
#include <Security/Security.h>
点击下载苹果封装好的KeychainItemWrapper。
https://developer.apple.com/library/ios/samplecode/GenericKeychain/GenericKeychain.zip
这个方法,目前我自己测试可以使用,并且ID固定。
据说:keychain里保存的信息不会因App被删除而丢失。
加上这一断代码测试后,我成功提交了我的应用。欢呼!