2011-12-31 114 views
0

我想每個月都會發出一個提醒視圖(例如每個月的第一天)以提醒用戶對我的應用進行評分。我在第一次打開應用程序時搜索了打開警報視圖的方法,但沒有解決我的問題的答案。任何人都可以幫我用下面的代碼。啓動一個UIalert查看月度

非常感謝。

- (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/"]]; 
    } 
} 

回答

1

如果真正要做到這一點(我建議你UX的緣故沒有),一個簡單的方法是寫一個NSDate對象添加到您的最後一次standardUserDefaults您的留言被顯示。你可能不需要整個日期,也許只是一個月和一天。在應用程序啓動時,將存儲日期與當前日期進行比較,以查看是否應該顯示警報。如果是,請更新保存的日期並顯示警報。

同樣,我建議你不要顯示警報。如果人們想評價你的應用,他們會。通知所做的唯一事情就是惹惱你的用戶,並可能爲你的應用產生負面評價。