简体   繁体   中英

Initiate an UIalert View monthly

I would like to make a alert view every month (eg 1st of Every month) for reminding users to rating my app. I searched the methods for opening up the alert view in the first time opening the app, but there is no answer on solving my problem. Could anyone help me with the following codes.

Many thanks.

- (void)viewDidLoad{
    [super viewDidLoad];

    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    NSString *alreadyRun = @"already-run";
    if ([prefs boolForKey:alreadyRun])
        return;
    [prefs setBool:YES forKey:alreadyRun];
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Rate and Comment" message:@"Thank you for choosing Art of Codes, your support could make this app better. Please rate and comment and tell us what you think."delegate:self cancelButtonTitle:@"Done" otherButtonTitles:@"Rate it!", nil];
    [alert show];
 }

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    // the user clicked one of the OK/Cancel buttons
    if (buttonIndex == 0)
    {
        NSLog(@"ok");
    }
    else
    {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/"]];
    }
}   

If you truly want to do this (and I suggest you don't for the sake of UX), an easy way would be to write an NSDate object to your standardUserDefaults of the last time your message was displayed. You might not want the whole date, perhaps just month and day. On app launch, compare the stored date to the current date to see if it's time to display an alert. If it is, update the saved date and display the alert.

Again, I suggest you do not display the alert. If people want to rate your app, they will. The only thing the notification will do is annoy your users and possibly spawn negative reviews for your app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM