Unique identifier for an iPhone app

后端 未结 13 1180
南笙
南笙 2020-11-29 18:33

For an iPhone app that submits images to a server I need somehow to tie all the images from a particular phone together. With every submit I\'d like to send some unique pho

相关标签:
13条回答
  • 2020-11-29 19:05

    Don't forget that in iOS 5 uniqueIdentifier will be deprecated you should use CFUUID instead of that

    0 讨论(0)
  • 2020-11-29 19:13

    By far the easiest and most appropriate way to obtain a unique identifier is to use the mechanisms Apple explicitly provides for obtaining one - [[UIDevice currentDevice] uniqueIdentifier]. You can not guarantee that the phone number will be unique to the device or that the device will even have a phone number. Beyond that, doing so is a horrible idea as it is a definite invasion of the user's privacy. Even the uniqueidentifier should be hashed if you are going to store it in any way.

    0 讨论(0)
  • 2020-11-29 19:14

    Interestingly, Apple has since deprecated the uniqueIdentifier in iOS 5 (as gN0Me mentioned). Here's the relevant TechCrunch article: http://techcrunch.com/2011/08/19/apple-ios-5-phasing-out-udid/

    Apple suggests that you no longer uniquely identify the device but instead identify the user. In most cases, this is excellent advice though there are some situations which still require a globally unique device ID. These scenarios are quite common in advertising. Hence, I wrote an extremely simple drop-in library which replicates the existing behavior exactly.

    In a shameless plug of self promotion, I'll link it here in the hope that someone finds it useful. Also, I welcome all and any feedback/criticism: http://www.binpress.com/app/myid/591

    Nevertheless, in your particular situation I would advise skipping the globally unique ID functionality my library provides as it's a bit overkill for your situation. Instead, I would generate a simple CFUUID and store it in NSUserDefaults. This ID would be specific to your application but would allow you to group all the photos for that "app install" in your database.

    In other words, by deprecating the uniqueIdentifier method, Apple is suggesting that you don't identify per device but instead per app install. Unless you are operating under specific conditions, chances are the per app ID fits your product better anyway.

    0 讨论(0)
  • 2020-11-29 19:14

    Here is some more information on a way to get it from iTunes which may be useful for testing purposes.

    0 讨论(0)
  • 2020-11-29 19:14

    You can use MAC address as a unique id. Following link will help you

    How can I programmatically get the MAC address of an iphone

    0 讨论(0)
  • 2020-11-29 19:16

    In order to Persist the Unique Identifier you create between installations, you could use the Keychain Made easy with SSKeychain: Simply set your UUID as follows:

            [SSKeychain setPassword:@"Your UUID" forService:@"com.yourapp.yourcompany" account:@"user"];
    

    and then call it again anytime you need it:

    NSString *retrieveuuid = [SSKeychain passwordForService:@"com.yourapp.yourcompany" account:@"user"];
    

    Note: The services and accounts must match exactly.

    Then, if the App is deleted and reinstalled, the UUID will persist with reinstallation.

    If you then want to share this UUID across devices, set up your app to use iCloud. You can then store the UUID in NSUserDefaults, sync with KeyValueStore, and then set the UUID in the new devices keychain with the code above.

    This answer would get extremely long if I typed code for all the above, but plenty of sample code around here to figure it all out.

    0 讨论(0)
提交回复
热议问题