Stornu2
Stornu2

Reputation: 2322

identifierForVendor.UUIDString is generating the same Id in different app

I have this code to get the UUID:

//Initialaze the keychain helper
KeyChainWarp * keychain =[[KeyChainWarp alloc] initWithService:@"KeyChainService" withGroup:nil];

//Get the data from the keychain.
NSData * data =[keychain find:@"UUIDString"];
if(data != nil)
{
    //Set the global variable.
    userId = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}
else
{
    //Get the UUIDString for the first time.
    NSData *value = [[UIDevice currentDevice].identifierForVendor.UUIDString dataUsingEncoding:NSUTF8StringEncoding];

    //Insert in the keychain.
    if([keychain insert:@"UUIDString" :value])
    {
        //Set the global variable.
        userId = [[NSString alloc] initWithData:[keychain find:@"UUIDString"] encoding:NSUTF8StringEncoding];
    }
}

The idea is to keep it persistent even if the user delete the App, until now I have been receiving different UUID from the function in different Apps, but now I have an App that is returning the same UUID from Another App.

What I always do is to copy and paste the project, change all the names in the .plist, change the bundle name and create new provisioning profiles, and until now all my Apps from the same device had different UUID.

I have installed all my Apps in my device and all returns different UUID, maybe I'm forgetting to change something.

Do I need to change another stuff in the .plist or in the build configuration?.

I have changed in the .plist "Bundle display name", "Bundle name", "URL identifier" and "URL Schemes" and the bundle name in the project, as far I remember I don't have to change anything else.

Thanks in advance.

Upvotes: 0

Views: 2943

Answers (2)

Stornu2
Stornu2

Reputation: 2322

As Blue Gene said in the accepted answer identifiedForVendor it is supposed to return the same UUID of all the Apps that have the same bundle id format, but in my case that was not the result I was getting until a few days ago, so I have sean a strange behavior in all my Apps until now, and I'm going to post my discovers here to help someone in the future.

Take care that this is not the right answer, and the supposed correct behavior is the one described in Apple Docs.

This is an example of how my bundle id where working until a few days ago:

Bundle Id Examples

com.company.clientnamewith4letters = new unique id

com.company.clientnamewith6letters = new unique id

com.company.sameclientnamewith4lettersaddingLightattheend = new unique id

com.company.sameclientnamewith6lettersaddingLightattheend = new unique id

But since a few days ago:

com.company.newclientnamewith6letters = new unique id

com.company.newdifferentclientnamewith6letters = same new unique id

com.company.newdifferentclientnamewith8letters = same new unique id

And so on...

All my old apps are returning different UUID but all my new apps are returning the UUID that Apple said is supposed to be, this behavior was wrong in my first 4 apps and correct in my new 6 apps.

Apple said that if all my apps start with com.company I'm supposed to get the same UUID but is not my case, I have to add that I have more than 2 years between the first App and my last App, my guess is that there was a bug and now is working properly.

I think the only difference is the time I generated the Provisioning Profiles, and my guess is that the added something new to guarantee that the UUID will be the same.

As I save that UUID in the KeyChain, I have tested in all my apps if now I was getting the new UUID and that was not the case, the old ones generate the same old and different between them UUID.

I hope this helps someone in the future.

Regards and happy coding.

Upvotes: 1

Eli Waxman
Eli Waxman

Reputation: 2897

In order for you to receive the same identifier for vendor you should be the same vendor.

Usually for apps from the App Store it should return the same UUID if used by the same app developer, however as written in the documentation:

Normally, the vendor is determined by data provided by the App Store. If the app was not installed from the app store (such as enterprise apps and apps still in development), then a vendor identifier is calculated based on the app’s bundle ID. The bundle ID is assumed to be in reverse-DNS format.

which means you should also provide the same bundle id for your apps, for example

app1 : com.myId.app1

app2 : com.myId.app2

then you will get the same identifierForVendor.

Look at the documentation here: identifierForVendor

Upvotes: 2

Related Questions