7

I would like to find out when a user first bought my app... so far, I havent found a clean way and a UDID seemed to be the only option.

Ideally there would be a receipt I can get via StoreKit but so far.. nada

have I missed something ? Does anybody have an idea?


The situation is that I have a subscription and the FIRST issue (from the time you buy the app should be free). If I reinstall at a later time.. I should always get the original issue)

example: I buy the app in 10.2010 I install and run it and get the subscription issue from 10.2010 for free (no in-app purchase) Now I delete the app I Install it 1.2013 and I only get the subscription from 10.2010 for free! NOT The new one

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • Store a flag in the keychain. –  May 03 '13 at 08:55
  • the keychain is also fragile, no?... is it preserved across app deletions? and what If I just restore the phone ^^ – Daij-Djan May 03 '13 at 08:56
  • It's non-volatile and it is backed up. –  May 03 '13 at 08:58
  • cool, I didn't know that.. that isn't bad. I guess I could still get rid of it I don't restore the backup though? – Daij-Djan May 03 '13 at 09:01
  • Yes, that's right. But you can't be 100% safe anyway. What if the user jailbreaks the phone and deletes the supposedly permanent data? etc. –  May 03 '13 at 09:01
  • But it is a hell of a lot better than what I do now! Thanks. (btw: why do pack the answers in comments?) – Daij-Djan May 03 '13 at 09:02
  • You can't know when the user first bought your app, only when he first launched it – Jerome Diaz May 03 '13 at 09:03
  • @JeromeDiaz Even that's not true. You can call `stat()` on your app binary. Amongst a lot of other information, it will give you the time it was written to disk (i. e. when it was installed). –  May 03 '13 at 09:04
  • @Daij-Djan Added an answer. –  May 03 '13 at 09:04

2 Answers2

7

You can just store a flag in the keychain. The contents of the keychain are preserved across app reinstalls.

To get the first installation time of your app, check when the first time the app binary has been written to disk:

if (flag_in_keychain_not_present()) {
    // installed for the first time
    set_flag_in_keychain();

    struct stat st;
    stat([NSBundle mainBundle].executablePath.UTF8String, &st);
    time_t installed = st.st_mtime;
}
  • Have you found any documentation that states "The contents of the keychain are preserved across app reinstalls." ? This seems to be the case, but I cannot find any documentation that says that is the expected behaviour. – Andreas Paulsson Sep 20 '13 at 18:37
  • @AndreasPaulsson Fair enough, I will search for the relevant documentation. Honestly, I no longer know how I know this, but the keychain **is** persistent. –  Sep 20 '13 at 18:39
  • 1
    Watch out! The answer above fetches when the binary was written... not the time the user installed it on the device. If you are installing and debugging the app from XCode they are one and the same, but if you install the app through TestFlight or the App Store they are not! – litso Apr 03 '14 at 21:57
1

I haven't used Store Kit yet, but tell me if I'm wrong,

1) it requires a server at a point or another

2) when we use it to "buy" (not a subscription or a consumable) something we can retrieve this purchase on all devices using the same iTunes Account

My point, create a in app purchase free item, when it passes through you server the first time store it in a database and next time it is called with the same account "enable" the issue corresponding to the first free purchase

Jerome Diaz
  • 1,746
  • 8
  • 15