アプリケーションを起動する前に、ユーザーに同意を求めています。したがって、appDelegate.mには次のものがあります。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
defaults = [NSUserDefaults standardUserDefaults];
if(![defaults boolForKey:@"warningAccepted"]){
UIAlertView *alert;
alert = [[[UIAlertView alloc] initWithTitle:@"Warning" message:@"Message... To continue, select \"OK\". To close the app, select \"Cancel\"." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil] autorelease];
[alert show];
}
return YES;
}
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0){
[defaults setBool:YES forKey:@"warningAccepted"];
[defaults synchronize];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[window addSubview:mainNavController.view];
} else {
[window addSubview:tabBarController.view];
}
[window makeKeyAndVisible];
} else {
// Close App, User hit cancel.
UIAlertView *alert;
alert = [[[UIAlertView alloc] initWithTitle:@"App Cannot Continue" message:@"The application cannot run until warning is accepted." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil] autorelease];
[alert show];
}
}
1つの問題は、ユーザーがキャンセルを押したときにelseが呼び出されないことです。もう1つの問題は、アプリの続行を停止する方法がわからないことです。私が見つけたところによると、Appleはあなたにアプリケーションを強制的に閉じることを望んでいません。あれは正しいですか?これをどのように実装すればよいですか?皆様のご協力に感謝いたします。