简体   繁体   English

每月启动UIalert View

[英]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. 我想每月(例如每月1号)进行一次提醒,以提醒用户对我的应用程序进行评分。 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. 如果您确实想执行此操作(并且我建议您不要出于UX的考虑),一种简单的方法是将NSDate对象写入上次显示消息时的standardUserDefaults中。 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. 通知唯一要做的就是惹恼您的用户,并可能对您的应用产生负面评价。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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