1

How can create same(unique) UUID and how can i use that for all IOS Devices.In my code UUID is different in different devices.

My code getting UUID is.

 NSString* uniqueIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; // IOS 6+ NSLog(@"UUId:: %@", uniqueIdentifier); 

Thanks Shabeer

3
  • 2
    I think the word "unique" says it all... Commented Sep 1, 2014 at 17:34
  • What does mean by unique UUID for all iOS devices? please provide more information. Commented Sep 2, 2014 at 5:27
  • Based on UUID i need to do some transaction between two devices application. Commented Sep 2, 2014 at 5:28

2 Answers 2

4

This method will create a unique string for every device.. Here SGKeyChain is a keychain wrapper. You can write this on your own.

+ (NSString *) uniqueDeviceIdentifier { NSString *deviceUUID = [[SGKeyChain defaultKeyChain] stringForKey:@"uniqueId"]; if (!deviceUUID) { if (!deviceUUID.length) { NSString *deviceUUID = @""; CFUUIDRef uuidRef = CFUUIDCreate(NULL); CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef); CFRelease(uuidRef); deviceUUID = [NSString stringWithFormat:@"%@",[NSString stringWithString:(__bridge_transfer NSString *)uuidStringRef]]; [[SGKeyChain defaultKeyChain] setObject:deviceUUID forKey:@"uniqueId" accessibleAttribute:kSecAttrAccessibleAlways]; } } return deviceUUID; } 
Sign up to request clarification or add additional context in comments.

1 Comment

This key need need to be saved in keychain to save in permanently otherwise it be different id every time.
1

As for getting a unique ID, I quite like the following code:

[[NSProcessInfo processInfo] globallyUniqueString] 

This uses the date, and the deviceId to make a great uniqueID every time. As for sharing it over devices, that is impossible. Each device is unique so you can't expect your code to figure out who's devices belong to who. If you do want it to do this, then you could go about it one of three ways:

  1. You could have a local login screen where you use the name (possibly scrambled) as the uniqueID. This would use a hard-coded scrambler so that the uniqueID is the same for each name, but different for each user.

  2. You could use a backend server like Parse to hold a uniqueId for each person. You can then login on your device and the UUID will be shared between the devices.

  3. Finally, if you simply want a random looking string (like 463GH529-GJRH-FRH4-FH53-58FH3), you could hardcode one which can be used across EVERY device, but this defeats the purpose of a UUID as everyone will have the same one - not very unique!

Hopefully one of these points will be useful to you.

1 Comment

@sabir I haven't worked much with bluetooth but I have done a lot with iBeacons so hopefully the concept is the same. You check for every bluetooth device and store them in an array. You then go through the array one by one and check for the one with the strongest signal (or even better, there may be a distance value which you can use to see which one is closer, though i can't guarantee it). Once you have the device with the strongest signal, simple get the UUID and do what you like with it!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.