0

Possible Duplicate:
iOS unique user identifier

For my application I need the phones uuid. I know that I can get it with

NSUUID  *uuid = [NSUUID UUID];

But everytime I restart the app, I receive a different value. So I cant use it like the old uuid (which was always the same).

What can I do to receive a stable and unique identifier?

Community
  • 1
  • 1
H3rrVorr4g3nd
  • 265
  • 1
  • 6
  • 16

3 Answers3

3

UUIDs are 128-bit values A UUID is made unique over both space and time by combining a value unique to the computer on which it was generated and a value representing the number of 100-nanosecond intervals since October 15, 1582 at 00:00:00.

So every second you will get a new UUID.

You can't receive a stable and unique id, instead you can save the received id in keychain or plist and use it.

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
2

You are thinking of the UDID (not UUID), which is deprecated and no longer allowed on the App Store.

Here's a technique to simulate it: https://stackoverflow.com/a/8677177/832111

Community
  • 1
  • 1
StilesCrisis
  • 15,972
  • 4
  • 39
  • 62
1

You can use OpenUDID library to generate unique UDID per device. It is available here. Fundamentally it uses Pasteboard. An example below

//First app, install->run->close->delete
UIPasteboard* board = [UIPasteboard pasteboardWithName:@"com.company.wtv" create:YES];
board.persistent=YES;// persistent to make what you write persist after your app closes, or gets deleted.
[board setValue:@"hello" forPasteboardType:@"com.company.wtv.sharedValue"];

//Second app, installed after first one is deleted and ran this one... While bundle identifier and bundle seed different (i tried it on adhoc, not really releasing the app, but i htink the same)
NSData* result=nil;
NSString*resultStr=nil;
result =[board valueForPasteboardType:@"com.company.wtv.sharedValue"];
resultStr=[[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding];// I got resultStr containing hello
msk
  • 8,885
  • 6
  • 41
  • 72