【iOS】起動時にUIAlertを出して評価ページに飛ばす
起動時に「このアプリを評価してください」とUIAlertにと出したい話。

こういう場合は、didFinishLaunchingWithOptionsにUIAlertについての記述をすれば良い。
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CGRect frameForWindow = [[UIScreen mainScreen] bounds];
window = [[UIWindow alloc] initWithFrame:frameForWindow];
//write about window
//ウインドウについて記載
[window addSubview:navigationController.view];
//From here about UIAlert and rating popup.
//manage displaying UIAlert by NSUserDefaults
//ここからUIAlertについて記載。表示するかどうかはNSUserDefaultsで制御する。
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSInteger executeTime = [userDefaults integerForKey: @"executeTime"];
NSInteger alertDispFlag = [userDefaults integerForKey: @"alertDispFlag"];
executeTime++;
//If this application is started 6 times or more and alertDispFlag == 0, then alert is displayed.
//もし6回以上起動していて、alertDispFlagが0なら表示する
if (executeTime > 5 && alertDispFlag == 0) {
// アラート表示
UIAlertView *alertView = [[UIAlertView alloc] init];
alertView.delegate = self;
alertView.title=NSLocalizedString(@"pleaseReview", @"Please Rate");
alertView.message=NSLocalizedString(@"appliciate", @"Please Rate this apps.");
[alertView addButtonWithTitle:NSLocalizedString(@"Review", @"Rate now.")];
[alertView addButtonWithTitle:NSLocalizedString(@"Later", @"Remind me later.")];
[alertView addButtonWithTitle:NSLocalizedString(@"nothanks", @"No, thanks.")];
[alertView show];
[alertView release];
}
[userDefaults setInteger:executeTime forKey: @"executeTime"];
[userDefaults synchronize];
return YES;
}
//UIAlartのデリゲート。UIAlertの動作を記載する。
//delegate to UIAlret
-(void)alertView:(UIAlertView*)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
switch (buttonIndex) {
case 0:
//go to rate page
[userDefaults setInteger: 1 forKey: @"alertDispFlag"];
[userDefaults synchronize];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:NSLocalizedString(@"reviewURL", @"") ]];
break;
case 1:
break;
case 2:
[userDefaults setInteger: 1 forKey: @"alertDispFlag"];
[userDefaults synchronize];
break;
}
}
review URLは、
itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=(数字9桁のapp id)&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software
です。