Is there any method to set a specific date during compilation that an app complied using ad-hoc distribution will expire and cannot be run some time later?
-
I want to provide a test version to some users. However, I want the app to be disable after a test period. Anything i can do then? – user6539552 Aug 02 '17 at 17:25
-
Possible duplicate of [Ad Hoc iOS Distribution Profiles become invalid](https://stackoverflow.com/questions/39941556/ad-hoc-ios-distribution-profiles-become-invalid) – Nazmul Hasan Aug 02 '17 at 20:07
4 Answers
simply it's NO you can not do anything with provision profiles with compile or run time. it's just manual thing for iOS app. you need to arrange according to your requirement like when to use development and when to ad-hoc or distribution. compiler does not contain any knowledge about the provision profiles.

- 2,200
- 17
- 26
The compiler doesn't "know" about the provisioning profile used to create and sign the binary. This is step too far along the build process.
The best thing you could do is revoke the ad-hoc distribution certificate (not profile).

- 2,024
- 23
- 42
-
1correct me if I'm wrong.. you revoke certificates, not profiles?. Revoking certificates prevent new installations, but previous installations will still work? – Marcio Romero Patrnogic Aug 02 '17 at 17:11
Provisioning profiles and certificates don't work that way.. if you need to restrict access to your app you have to do it by code.
Keep in mind that jailbroken devices may be able to bypass your validations. Also if you are using the device date to restrict access, a user that has changed the device hour and date will be able to access.

- 1,156
- 7
- 16
An easy workaround for this that I have found useful. Hardcode your expiration date, and compare it to the current date every time your app loads:
NSDate* todaysDate = [NSDate Date];
NSDate* expirationDate = [NSDate dateFromString: expirationStr];
if([todaysDate laterDate:expirationDate] == todaysDate){
[self performSegueWithIdentifier:@"segueToExpirationVC" sender:self];
}
In viewDidLoad of my initialViewController I check if the current date is past the "expiration date" I have set for the app. If it is, then I perform a segue to a view controller with no buttons to segue out of the VC. On this ViewController you can display a message along the lines of "The beta of this app has expired." I often will also include a survey on this ViewController to ask my beta testers about their experience using the app.
This effectively makes the app unusable, as on the expiration date you set it will transition to a view controller that can't be left.
Note: you can do something similar by programmatically changing the initial view controller if the same Date comparison conditions are met.

- 40
- 1
- 11
-
This doesn't answer the OP question, namely, how to read an ad hoc profile's expiry date in code. – ajmccall Aug 03 '17 at 09:06
-
@ajmccall As I said above, it is a workaround that provides the same functionality he is looking for. "Is there any method to set a specific date during compilation that an app complied using ad-hoc distribution will expire and cannot be run some time later?" This approach effectively sets the app to expire by transitioning to a vc that can't be left once the certain date requirements are met. – FightOn Aug 03 '17 at 12:19
-
1@ajmccall Additionally, the OP did not ask "how to read an ad hoc profile's expiry date". I believe it does answer his question. – FightOn Aug 03 '17 at 18:02