问题
If that isn't possible, then how may I do it after, say, 3 minutes of app usage? This is going to be used for a Rate Us alert but I would rather the user have some time to actually use the app before it asks for them to rate.
回答1:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)options {
// ...
if ([self plusPlusLaunchCount] == 2) {
[self showRateUsAlert];
}
return YES;
}
- (void)showRateUsAlert {
// show the Rate Us alert view
}
- (NSInteger)plusPlusLaunchCount {
static NSString *Key = @"launchCount";
NSInteger count = 1 + [[NSUserDefaults standardUserDefaults] integerForKey:Key];
[[NSUserDefaults standardUserDefaults] setInteger:count forKey:Key];
return count;
}
回答2:
Instead of making a "Rate Us" alert yourself, why don't you use third-party libraries? This kind of thing has been done so many times anyway.
This is one of a really good one : iRate
Not exactly answer to your question in the title.
回答3:
You need to set an NSTimer
for the time interval you want to show the alert. When the application launches start the timer and after the interval you set finishes, display the alert.
回答4:
I would suggest you use DidBecomeActive which is called every time you launch app, and come from background/sleep mode:
You would need to cancel the timer in case user doesn't use app for so long.
- (void)applicationDidBecomeActive:(UIApplication *)application{
// Override point for customization after application launch.
rateUsTimer = [[NSTimer scheduledTimerWithTimeInterval:180
target:self
selector:@selector(showRateUsAlert)
userInfo:nil
repeats:NO] retain];
}
- (void)applicationWillResignActive:(UIApplication *)application{
[rateUsTimer_ invalidate];
[rateUsTimer_ release];
rateUsTimer = nil;
}
- (void)applicationDidEnterBackground:(UIApplication *)application{
[rateUsTimer_ invalidate];
[rateUsTimer_ release];
rateUsTimer = nil;
}
- (void)showRateUsAlert {
//Here you present alert
[rateUsTimer_ release];
rateUsTimer = nil;
}
来源:https://stackoverflow.com/questions/11076960/make-a-uialertview-show-after-second-launch