Apple has banned UUID applications since January 1. So we need to replace it with some methods. Below I will replace the UUID with the keychain access.
For the Keychain application, Apple provides an example program named GenericKeychain. Here: Example.
1. import the Security. framework file to the database and import the KeychainItemWrapper. h and KeychainItemWrapper. m files to the project, and reference the header file: # import "KeychainItemWrapper. h"
2. code example:
[Plain]
NSString * str = nil;
KeychainItemWrapper * keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier: @ "UUID" accessGroup: @ "com. xxx. xxx"];
NSString * uuidStr = [keychainItem objectForKey :( id) kSecValueData];
If (uuidStr. length = 0 ){
NSString * myUUIDStr = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
[KeychainItem setObject: myUUIDStr forKey :( id) kSecValueData];
Str = myUUIDStr;
}
Else {
Str = [keychainItem objectForKey :( id) kSecValueData];
}
NSLog (@ "=====%@", str );
Return str;
NSString * str = nil;
KeychainItemWrapper * keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier: @ "UUID" accessGroup: @ "com. xxx. xxx"];
NSString * uuidStr = [keychainItem objectForKey :( id) kSecValueData];
If (uuidStr. length = 0 ){
NSString * myUUIDStr = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
[KeychainItem setObject: myUUIDStr forKey :( id) kSecValueData];
Str = myUUIDStr;
}
Else {
Str = [keychainItem objectForKey :( id) kSecValueData];
}
NSLog (@ "=====%@", str );
Return str;
The imported Security. framework is because the KeychainItemWrapper file only encapsulates Security and is more conducive to our calls.