4
votes

I am making an order booking app. I need to send a unique key from the iPhone/iOS device to the server.

Can I use GUID of iPhone? i.e [UIDevice uniqueIdentifier] Is it legal? Legal means will apple accept that?

What is the best property to use to uniquely identify an iPhone or iOS device? If not then what would be the other way to uniquely identifying device.

Actually i need booking reference no. generated by app. must be unique.

5
Where did you get this GUID? What API?p.campbell
I'm not entirely sure what you mean by "is it legal"..NotMe
I advise you to identify the user not the device. The user can change the device. ;-)Sandro Meier
I need booking reference no. generated by app . must be unique. So how can i do thatMann

5 Answers

5
votes

Apple has announced that in May 2013 will start to reject application that use the UDID to track the user behavior

this is an alternative to the UDID:

You can create a category of UIApplication , UIDevice or as you prefere like this (ARC example)

@interface UIApplication (utilities)
- (NSString*)getUUID;
@end

@implementation UIApplication (utilities)

- (NSString*)getUUID {

    NSUserDefaults *standardUserDefault = [NSUserDefaults standardUserDefaults];

    static NSString *uuid = nil;

    // try to get the NSUserDefault identifier if exist
    if (uuid == nil) {

        uuid = [standardUserDefault objectForKey:@"UniversalUniqueIdentifier"];
    }

    // if there is not NSUserDefault identifier generate one and store it
    if (uuid == nil) {

        uuid = UUID ();
        [standardUserDefault setObject:uuid forKey:@"UniversalUniqueIdentifier"];
        [standardUserDefault synchronize];
    }

    return uuid;
}

@end

UUID () is this function

NSString* UUID () {

    CFUUIDRef uuidRef = CFUUIDCreate(NULL);
    CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef);
    CFRelease(uuidRef);
    return (__bridge NSString *)uuidStringRef;
}

this generate an unique identifier stored into the NSUserDefault to be reused whenever the application need it - This identifier will unique related to the application installs not to the device, but can be used for example to take trace about the number devices subscribed the APN service etc...

After that you can use it in this way:

    NSString *uuid = [[UIApplication sharedApplication] getUUID];
4
votes

There is no GUID that I am aware of, do you mean [UIDevice uniqueIdentifier]? You may use that, but it’s getting deprecated in iOS 5, so that you’d better come up with some other means of identificating your devices.

3
votes

Create a UUID: A string containing a UUID. The standard format for UUIDs represented in ASCII is a string punctuated by hyphens, for example 68753A44-4D6F-1226-9C60-0050E4C00067.

+ (NSString *)newUUID
{
    CFUUIDRef theUUID = CFUUIDCreate(NULL);
    CFStringRef string = CFUUIDCreateString(NULL, theUUID);
    CFRelease(theUUID);
    return (NSString *)string;
}
1
votes

I won't refer to what is under NDA, but give a try to this solution, as the author advertises "It generates a unique identifier based on the mac address of the device in combination with the bundle identifier." However be warned that jailbroken devices can change their mac address AFAIK.

0
votes

With iOS 6 came identifierForVendor, it can be used across multiple apps from the same vendor and although it identifies a device you can use it in combination with iCloud's key-value store for example to identify the user across devices.

Ole Begemann explains it all nicely on his blog: http://oleb.net/blog/2012/09/udid-apis-in-ios-6/