Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Sunpath

macrumors newbie
Original poster
Jul 13, 2018
1
0
Hi there.

I am currently building an IOS 12 app and I wanted to know how to program an expiration date into it. The app will function as a digital membership card. After a person downloads it, I would like it to stop working after period of time, say 6 months after its downloaded. So for example someone downloads it on January 1st it will expire on June 1st, and if another person downloads it on march 1st it would expire on September 1st. How would I go about doing this? Relatively new to this. Thank you in advance.
 
First - Apple would almost certainty reject this app.

With that said - if you still want to attempt it, you'll have to start your countdown when the app is first launched. The action of someone simply downloading your app does not present you, the dev, with an opportunity to execute code.

On initial launch, grab the current date and save it to UserDefaults. AppDelegate's application:didFinishLaunching is a good spot to do this. Now each time the app is brought back to the foreground after being sent to the background, check the saved date of the initial launch that you saved in UserDefaults. Then do whatever you want to do after the comparison.

Keep in mind that this is all useless since the user can uninstall the app and redownload it, resetting UserDefaults for the app. You would have to assume they have an iCloud account, and then set a flag saved in their private DB within your apps iCloud container. This would require you to get familiar with CloidKit.

I think you'd be better suited by building a backend system that can facilitate memberships tied to customer logins and make an iOS app which acts as a client to that system.

It's almost 2AM here, but hopefully I shared a bit of insight.
 
Yeah, there’s no way you can do this that couldn’t pretty easily be defeated by the user. Heck, they can just change their date on their device. Set it forward ten years, launch the app for the first time, then set the date back. Lots of scenarios where they can set the date backward or forward. Or they can uninstall and reinstall. If you try to capture a unique device identifier they can change it. Only way it works is if you have a backend system tied to verifiable identity information. You can make sure that that identity times out, and that’s about it. For example, make them log in with a phone number or credit card number or email address or whatever, send the info to your server, which keeps track of end dates, and each time you run the app have the app verify with the server that the phone number or credit card number hasn’t timed out.

But Apple won’t approve such an app.
 
You could try making a subscription app (via an in-app purchase) with a server component that checks to see whether the subscription is paid-up before delivering some needed data for the app to operate. Apple now allows offering the first period of subscription free.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.