我希望用户在启动应用程序之前接受协议。所以在 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];
}
}
一个问题是当用户点击取消时 else 永远不会被调用。另一个问题是我不确定如何阻止应用程序继续运行。根据我的发现,Apple 不希望您强制关闭应用程序。那是对的吗?我应该如何实施呢?感谢您所有的帮助。