/ Published in: Objective C
Do you need you app to do something when it is first run on a certain computer? Do you need to know if it has been run before? Enter the following code into your Application Delegate.
This code creates a BOOL that is created when the app is run. The if-else statement reads the value of the BOOL -- Yes or No. NOTE: You'll notice that if you run the app from xcode with the run button it says "Not run before". When you run it again it still says that. In order to truly test locate you apps Debug .app application then run that. Xcode clears out the data when you run it again. IT DOES WORK though, so don't worry if running you app in Xcode still gives you the Not Run Before result.
This code creates a BOOL that is created when the app is run. The if-else statement reads the value of the BOOL -- Yes or No. NOTE: You'll notice that if you run the app from xcode with the run button it says "Not run before". When you run it again it still says that. In order to truly test locate you apps Debug .app application then run that. Xcode clears out the data when you run it again. IT DOES WORK though, so don't worry if running you app in Xcode still gives you the Not Run Before result.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
-(void)awakeFromNib{ BOOL hasRanBefore = [defaults boolForKey:@"hasRanBefore"]; [defaults setBool:YES forKey:@"hasRanBefore"]; [defaults synchronize]; if (hasRanBefore) { [iRanBefore runModal]; } else { [iDidNotRunBefore runModal]; }
URL: http://programmersweb.blogspot.com/2011/05/checking-if-you-app-has-been-run-before.html