Make a UIAlertView show after second launch

杀马特。学长 韩版系。学妹 提交于 2019-12-04 15:02:40
- (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;
}

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.

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.

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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!