Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using a unique identifier of iPhone or iOS device

Tags:

ios

iphone

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.

like image 591
Mann Avatar asked Dec 13 '22 09:12

Mann


1 Answers

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];
like image 70
Manu Avatar answered Jan 05 '23 11:01

Manu