Reputation: 2833
I want to create UUID, I have code below which can create UUID, how can I create UDID with multiple vendors same ID in iOS7?
+ (NSString*) stringWithNewUUID
{
CFUUIDRef uuidObj = CFUUIDCreate(nil);
NSString *newUUID = (NSString*)CFUUIDCreateString(nil, uuidObj);
CFRelease(uuidObj);
return newUUID;
}
Upvotes: 5
Views: 13333
Reputation: 2833
I have created a vendor ID and then saved it with keychain, which I am retaining for next time using KeychainWrapper keychainStringFromMatchingIdentifier:...
Upvotes: 5
Reputation: 2464
I followed Sandeep Khade's answer and made following code using PDKeychainBindings. It's same as using NSUserDefaults but it keeps identifier in keychain which saves data even when application is deleted.
+ (NSString *)uniqueVendor {
PDKeychainBindings *keychain = [PDKeychainBindings sharedKeychainBindings];
NSString *uniqueIdentifier = [keychain objectForKey:kKeyVendor];
if (!uniqueIdentifier || !uniqueIdentifier.length) {
NSUUID *udid = [[UIDevice currentDevice] identifierForVendor];
uniqueIdentifier = [udid UUIDString];
[keychain setObject:uniqueIdentifier forKey:kKeyVendor];
}
return uniqueIdentifier;
}
Upvotes: 0
Reputation: 1826
This method returns random UUID in iOS 6 and above
[[UIDevice currentDevice]identifierForVendor]
Upvotes: 5
Reputation: 20048
The CFUUIDCreate
function produces a version 4 UUID which is taken entirely from a pseudo-random number generator. There are no timestamps or MAC addresses embedded in this type of UUID. (That refers to the little-used version 1 flavour.) These are safe to use for nearly all applications.
Upvotes: 5
Reputation: 2308
The UUID that the code produces above does not have a recoverable time stamp in it. It's just a string that looks something like this: E1D87006-7CD0-4E28-9768-624DA92F75D6
Upvotes: 2