How can i get user Device Id in iOS? - ios

I want the device id of user mobile bcz I want to store it in database while submitting the form,so that whenever user uninstall the app and again reinstall the same at that time he will get all record which is submitted previously so he need not to submit the data again.I used library but it will return the same id for all device.please help.Thanks in advance.

Official Documentation answer
#property(nonatomic, readonly, retain) NSUUID *identifierForVendor
NSString *identifier = [[UIDevice currentDevice].identifierForVendor UUIDString];
The value of this property is the same for apps that come from the same vendor running on the same device. A different value is returned for apps on the same device that come from different vendors, and for apps on different devices regardless of vendor.
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.
On iOS 6, the first two components of the bundle ID are used to generate the vendor ID. if the bundle ID only has a single component, then the entire bundle ID is used.
On IOS 7, all components of the bundle except for the last component are used to generate the vendor ID. If the bundle ID only has a single component, then the entire bundle ID is used.
If the value is nil, wait and get the value again later. This happens, for example, after the device has been restarted but before the user has unlocked the device.
The value in this property remains the same while the app (or another app from the same vendor) is installed on the iOS device. The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them. The value can also change when installing test builds using Xcode or when installing an app on a device using ad-hoc distribution. Therefore, if your app stores the value of this property anywhere, you should gracefully handle situations where the identifier changes.

you can use unique device id FOR IOS6+
NSString *identifier = [[UIDevice currentDevice].identifierForVendor UUIDString];

Related

How could I get identifierForVendor for any app (not developed by me)?

My goal is to obtain the identifierForVendor for a specific app that is on the App Store and that I have NOT developed nor have access to. Lets say this app's bundle id is com.example.app
And just to preface, I was able to grab the identifierForVendor of com.example.app by sniffing the network requests. However, this is not an efficient or scalable way to get it for multiple devices. So, I am looking into other methods.
I have tried to get the identifierForVendor of com.example.app by creating a custom iOS app on Xcode with the bundle id com.example.test
I was hoping the identifierForVendor would be the same considering their documentation notes that apps with the same bundle id will have the same identifierForVendor, but it was not. It seems that the identifierForVendor is also based on the developer profile or something.
Is there anyway for me to get this identifierForVendor value of an external app?
The short answer is that you cannot.
Apple does not provide any details on how this identifier is computed.
The identifier is unique for apps with the same initial bundle id components for a given developer on each device.
For example, apps with bundle ids com.example.app1 and com.example.app2, both from developer1 would have the same identifierForVendor on a given device.
An app with the bundle id com.example.app3 on the same device but from a different developer would have a different identifierForVendor; that is the for vendor bit.
Even if you use the same bundle ID prefix you won't get the same identifier as an app from another developer.
You should also note:
The value in this property remains the same while the app (or another app from the same vendor) is installed on the iOS device. The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them.

Unusual case of VENDOR IDENTIFIER getting same in different devices for same app downloaded from App Store

recently I got into iOS development and I got a task of examining the application which is already in App Store . But I found something unusual ... Two different users when loging through two different devices through my application which is downloaded from App Store returns same vendor ID ...... is this the expected one ? Because according to the APPLE DOCUMENTS VENDOR ID MUST BE DIFFERENT FOR DIFFERENT DEVICE REGARDLESS OF VENDOR if the app is downloaded from App Store . Please clarify here .
The code which I am using is :
NSString *UString = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
NSLog(#"Vendor ID %#", UString);
After several research and practical results I found several characteristic of VendorID:
VENDOR ID will be unique for every device I.e if a same app is downloaded on two devices from App Store , it will surely return different VENDOR ID. VENDOR ID is calculated based on AppStore data in this case
VENDOR ID will be same for every app on a single device which is from same vendor . That is if I have 5 apps from a VENDOR named A in my device .. ALL THESE 5 APPS WILL HAVE SAME VENDOR ID. If we uninstall one app and reinstall again the VENDOR ID will not change . For VENDOR ID to change we must uninstall all 5 apps .
VENDOR ID in newer iOS will also change if we are installing the build using XCODE or development certificate on different device I.e every device will have a different VENDOR ID for same app . In this case vendor ID is calculated based on BUNDLE ID . For older iOS similar BUNDLE ID for 2 apps may produce identical VENDOR ID .
VENDOR ID is always a 32 bit string
VENDOR ID is not a device identifier instead it’s a UUID through this we can’t identify the details about the device
UPDATION CASE
It is not supposed to change when updating the app from app store as is described in the documentation.
If you are updating an itunes-installed app, then updating it using Xcode or an ipa based on ad hoc provisioning or any provisioning, you will get a different value. You need to make it consistent, Adhoc to adhoc, dev to dev, app store to app store.
Installing and Reinstalling app when the vendor has only single app
Unless the user has another app from the same vendor installed, this id will change after deleting and reinstalling. In your case, where there is no other app by the same vendor, this means that the ID will change,

Does two device will have the same 'UUID'

In my iOS app, I have to restrict the user to use iOS app per device. To do this I found a solution that we can use the identifierForVendor method of UUID (Universally Unique Identifier) which will generate a unique ID to uniquely identify an app on a device. (Here, I am not using UDID (Unique Device Identifier) because Apple rejects apps if the app uses UDID).
So my question as is there any possibilities that the two devices will have the same UUID. any idea?
EDIT 1:
I have one more doubt as if I installed the same app on different two devices and save its UUID string into the device KeyChain. Both devices have same iCloud account. Now while doing iCloud sync for this two devices, is one my device KeyChain will gets overwritten?
EDIT 2:
I have found answer for EDIT 1 as 'Yes, through iCloud Keychain, the keychain would be synced to another one of my devices, and I’d get the same device identifier from here and from below answer too'
For the item to be synced with iCloud keychain, I’d need to explicitly set the kSecAttrSynchronizable attribute. Using the SecItem API, we can set this attribute while adding a keychain item.
Is there any tutorial how to add item in Keychain (Without third party libraries)?
No, Two device does not have the same UUID. I am 100% Sure about it. So go with identifierForVendor method.
But, The UUID may be changed when you reinstall the the application in your device (If there is not other application for the same vendor).
The value in this property remains the same while the app (or another app from the same vendor) is installed on the iOS device. The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them. The value can also change when installing test builds using Xcode or when installing an app on a device using ad-hoc distribution. Therefore, if your app stores the value of this property anywhere, you should gracefully handle situations where the identifier changes.
EDIT
YOUR QUESTION
I have one more doubt as if I installed the same app on different two devices and save its UUID string into the device KeyChain. Both devices have same iCloud account. Now while doing iCloud sync for this two devices, is one my device KeyChain will gets overwritten?
ANSWER
YES. Your keychain will gets overwritten. So you have same UUID for both 2 devices.
I thought is NO!
The value of this property is the same for apps that come from the same vendor running on the same device. A different value is returned for apps on the same device that come from different vendors, and for apps on different devices regardless of vendor.
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.

apple device UUid getting changed after installing the updated version on IOS 7

To getting the user's device UUID in objective c I have using
[UIDevice currentDevice].identifierForVendor.UUIDString
In ios 6, now when I am trying to download the IOS-7 version of that app whole UUID getting changed. Not getting any clue how to solve this.
It's looking like this,
When installing the IPA === 0849EC56-XXXX-XXXX-XXXX-EF1625FB58C8
​After downloading the same app from app store it's giving UUID - 285E6931-XXXX-XXXX-XXXX-08D85052E180​
UUIDString is not unique for iOS device its unique for your app.
Read the apple doc
identifierForVendor
An alphanumeric string that uniquely identifies a device to the app’s vendor. (read-only)
#property(nonatomic, readonly, retain) NSUUID *identifierForVendor
The value of this property is the same for apps that come from the same vendor running on the same device. A different value is returned for apps on the same device that come from different vendors, and for apps on different devices regardless of vendor.
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.

Save a text file on iOS Directories from app

I am developing a program where I need to store a unique device_id since I cant get a unique identifier (like MAC Address) for every device, because it is deprecated by Apple.
What I want to do is, store a file in a specific directory of iOS where even the user deletes my iOS app this file wont be deleted. I am saying this because I used NSUserDefaults but the data stored from it get deleted if the user deletes its application.
*P.S Or if there is an alternative way to identify every device with its unique_id, suggestions are welcomed!*
You should use KeyChain to save info that should not be deleted together with app.
https://developer.apple.com/library/ios/documentation/Security/Reference/keychainservices/Reference/reference.html
UPDATE
This SO thread could be useful for you Saving/Reading to/from KeyChain
I need to store a unique device_id since I cant get a unique
identifier
It is not 100% correct. You can use
[ UIDevice currentDevice ].identifierForVendor
From Apple's docs :
The value of this property is the same for apps that come from the
same vendor running on the same device. A different value is returned
for apps on the same device that come from different vendors, and for
apps on different devices regardless of vendor.
Normally, the vendor is determined by data provided by the App Store.
I 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.
On iOS 6, the first two components of the bundle ID are used to
generate the vendor ID. if the bundle ID only has a single component,
then the entire bundle ID is used. On IOS 7, all components of the
bundle except for the last component are used to generate the vendor
ID. If the bundle ID only has a single component, then the entire
bundle ID is used.

Resources