0

I am trying to check whether user has installed this app on his iOS device before or not.

For example I install app X , then Uninstall it, and again Install it.

I want that app X be able to detect that the device had installed this app before and this is a re-installation.

Update

By thanks to all friends that shared solutions like keychain, vendor Id and etc. The main subject that I should notice (as mentioned in comments) is that; Is there a solution that works even after system restore or system factory reset? According to @Andrea's answer using receipts may work but what about the cases that we want to publish the app in enterprises account? Or what if user uses a jailbreak device and install the app with and IPA? Some times because of security problems we want to detect that whether this app is installed before or not? So how we can detect it?

Husein Behboudi Rad
  • 5,434
  • 11
  • 57
  • 115
  • Man, if it is so crucial to detect previous installation of the app maybe you should consider an external piece of hardware, like a Bluetooth dongle. – Juan Catalan May 27 '15 at 15:36

6 Answers6

1

Maybe trying to check the app receipt you can infer the original purchase date (even if the app is free it comes with a receipt), but this could be difficult.
If you want to do that you can can add a flag to the keychain. Keychain values persist after an uninstall, but not after a system restore.
Of course this can work only in future releases.

Andrea
  • 26,120
  • 10
  • 85
  • 131
0

iOS is built to reserve a portion of disk to each application installed, when you uninstall application the space is erased so there isn't a "cookie" that describes when app has been installed. You can reach your goal in two ways: through the keychain, for instance you save a value with specific key and you check every installation that key or through a simple backend call that send you the date o whatever you want. I think the first solution is better.

dpizzuto
  • 412
  • 1
  • 5
  • 14
  • If I use keychain, if user reset the app the data remains? – Husein Behboudi Rad May 24 '15 at 09:45
  • Keychain is not depending from the app but it's a System tool for maintaining values, typically password. Yes, the key will be remain even the user uninstall application – dpizzuto May 24 '15 at 09:48
  • I mean if the user reset factory the device. According to Andrea's answer it is not presist after system restore (If system restore is what I mean factory reset) so it is not good idea for me – Husein Behboudi Rad May 24 '15 at 09:49
  • Yes, if user reset and don't restore backup the keychain will be reset.At this point the only "secure" solution it's the backend call – dpizzuto May 24 '15 at 09:56
  • So please check my comments with Lajos Arpad. At this point we need a unique identifier. Witch unique identifier we can use for this propose that be persist after system reset? – Husein Behboudi Rad May 24 '15 at 10:00
0

I would define a method to uniquely identify a device. Whenever an install is issued on a device, I would send a request to a server, where device keys are stored. If the key is not already present in the database, then I would store it, otherwise the install has been already issued.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • what is the identifier you use? I find openUDID but it seems that the data is not persist after system reset – Husein Behboudi Rad May 24 '15 at 09:47
  • I have an aversion for smartphones, but as general knowledge, it seems that UDID would be a good first guess. – Lajos Arpad May 24 '15 at 09:56
  • Apple do not allow using UDID in ios 7 and ios 8 – Husein Behboudi Rad May 24 '15 at 09:58
  • I am sorry to hear that. Then you need something else. I would research the possibilities to uniquely identify an Apple device if I were you. I am sure my idea is good, but I do not know how to apply it since I do not use/develop IOS – Lajos Arpad May 24 '15 at 10:14
  • yes the idea is good but it seems that in iOS, finding a unique identifier is the problem – Husein Behboudi Rad May 24 '15 at 10:17
  • You can get the IP address, which more-or-less implies the place the user is in. And you can pair it with the name of the device user. That is not unique and not exact, but it is better than nothing. – Lajos Arpad May 24 '15 at 10:23
  • 1
    In iOS 6 Apple included NSUUID Class to generate unique identifiers. – Juan Catalan May 25 '15 at 13:52
  • @HuseinBehbudiRad, to me it seems that Juan Catalan has found the missing ingredient. – Lajos Arpad May 26 '15 at 09:14
  • @JuanCatalan our goal is to have a unique identifier per device that be unique even after system factory reset and system restore; as I know NSUUID generates a new random number after each call. it means that is is even not unique per app(not per app nor per device) so it is not suitbale – Husein Behboudi Rad May 26 '15 at 11:06
  • @HuseinBehbudiRad You're right, please see my answer on how to accomplish what you want. – Juan Catalan May 26 '15 at 13:58
0

You can save something to keychain and then try to read it.

George
  • 756
  • 1
  • 9
  • 16
0

As the OP mentions in one comment Apple does not allow access to the device UDID so we need a different approach to uniquely identify the user.

In order to get an identifier that uniquely identifies the user you could use:

[[UIDevice currentDevice] identifierForVendor]

But be careful, according to Apple documentation:

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.

A possible solution to this is to store the identifier in NSUserDefaults and also in the server and have a logic that at startup checks if there is a change in the identifier. In that case you could update the identifier locally and in the server to provide continuity for your analytics, for example.

For example to check for a change in the identifier:

NSString *previousUUID = [[NSUserDefaults standardUserDefaults] stringForKey:DEVICE_UUID];
NSString *currentUUID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
BOOL UUIDChanged = ![previousUUID isEqualToString:currentUUID];
// Handle this situation in your backend to offer continuity in your analytics

I have three apps in the App Store that use this and were approved by Apple without problems.

Juan Catalan
  • 2,299
  • 1
  • 17
  • 23
  • does device keeps NSUserDefaults from an application even after we uninstall it??! Also does this data do not change or remove after system restore or system factory reset? – Husein Behboudi Rad May 27 '15 at 04:37
  • actually it is important for us to detect reinstall even after system restore or system factory reset. – Husein Behboudi Rad May 27 '15 at 04:40
  • @HuseinBehbudiRad For what you want to accomplish then, you'll have to use the Keychain. Please look into this post for a solution: http://stackoverflow.com/questions/6993325/uidevice-uniqueidentifier-deprecated-what-to-do-now. Scroll down until you find the answer that deals with the keychain. – Juan Catalan May 27 '15 at 15:32
  • Sorry man I somehow downvoted your answer and found out to late to undo it lol – Arjan May 23 '23 at 22:00
-3

You can use APNS. Apple push notification service.

Device token never will change whatever device reset.

So, you can use Push notification.

Push notification(device token) is unique for each device and always will be same.

When app will install save device token on your server database so, whenever app will again install on same device you can check device token from server database.

Sandeep Agrawal
  • 425
  • 3
  • 10
  • 1
    So here is a challenges: - The problem is that when user do not allow to to the app to send push. As I understand, when app try to get the push id, the device ask users whether they allow to have push or not, if user do not allow, then we have not any push Id to save on server side. how we can fix it? Also there is some questions too: - Is Apple at any documentations said that push token is unique for all devices? - If someone reset factory the device or restore it, then it will remain same? – Husein Behboudi Rad May 25 '15 at 04:04
  • 2
    Device token changes, so you still have the problem of handling this. Please check Apple documentation. On top of that it is an overkill to use push notification service for this, it forces you to declare the use of push notifications and Apple will definitively check what use are you making of this, possibly rejecting your app if you don't use push at all. – Juan Catalan May 26 '15 at 14:49