DiscoveryOV
DiscoveryOV

Reputation: 1073

Make a UIAlertView show after second launch

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.

Upvotes: 2

Views: 1246

Answers (4)

DarthMike
DarthMike

Reputation: 3481

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;
}

Upvotes: 0

X Slash
X Slash

Reputation: 4131

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.

Upvotes: 1

rob mayoff
rob mayoff

Reputation: 385610

- (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;
}

Upvotes: 6

Mansi Panchal
Mansi Panchal

Reputation: 2357

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.

Upvotes: 0

Related Questions