首次启动应用程序时 iPhone 通知
我希望用户在启动应用程序之前接受协议。因此,在 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 永远不会被调用。另一个问题是我不确定如何阻止应用程序继续运行。据我所知,苹果不希望你强制关闭应用程序。这是正确的吗?我应该如何实施这个?感谢您的所有帮助。
I'm wanting the user to accept an agreement before the application is launched. So in the appDelegate.m I have the following:
- (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];
}
}
One problem is that the else never gets called when the user hits cancel. The other problem is that I'm not sure how to stop the app from continuing. From what I have found, Apple does not want you to force the application to close. Is that correct? How should I go about implementing this? Thanks for all of your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,如果您强制退出,Apple 将拒绝您的申请。我可以告诉;-)另一个 UIAlertView 说用户如果不接受就不能继续应该这个技巧(只是不要在上面放置任何按钮,这样用户就无法关闭它)
关于 else 范围,它不会通过它吗,或者 UIAlertView 不显示?用断点检查一下。此外,当
(buttonIndex == 0)
表示用户触摸了“取消”按钮时,这不是吗?Yes, Apple will reject your application if you force to exit. I can tell ;-) Another UIAlertView saying that the user cannot continue without accepting should de the trick (Just don't put any button on it so the user can't dismiss it)
About the else scope, does it not pass through it, or the UIAlertView doesn't show ? Check it with a breakpoint. Further more, isn't when
(buttonIndex == 0)
means that the user touched the "Cancel" button我已经成功地使用此委托方法:
并确保您的应用程序使用alertView 的cancelButtonIndex 和firstOtherButtonIndex 属性,以便您处理正确的按钮;我认为取消按钮目前通常索引为零,但这可能会改变。
I have had success using this delegate method instead:
And make sure that your application uses the cancelButtonIndex and firstOtherButtonIndex properties of the alertView so that you process the correct button; I think the cancel button is usually index zero at the moment but this could potentially change.
处理 EULA 的推荐方法是在您向 iTunes 提交申请时提交。这允许最终用户在下载您的应用程序之前阅读 EULA。
如果您想强制用户在使用应用程序之前接受 EULA,您可能应该将该协议放入可嵌入到应用程序中的 HTML 文件中。当您的应用程序启动时,在 UIWebView 中显示 HTML。 (只需几行代码。)不要尝试将其压缩到警报中。
您不能“退出”该应用程序。您可能希望在网络视图中显示 EULA,并在工具栏中或网页上的按钮中提供“接受”和“拒绝”选项。如果用户选择“拒绝”,那么您可能会弹出一条警报,要求从其设备中删除该应用程序。这个想法是他们可以滚动网络视图,但在点击“接受”之前不能继续。
我不确定苹果是否会允许这样做,这肯定会让你的最终用户感到沮丧。
The recommended way to handle an EULA is to submit it when you submit the application to iTunes. This allows an end user to read the EULA prior to downloading your application.
If you want to force the user to accept an EULA prior to using the application, you should probably put the agreement into an HTML file which you can embed within the application. Display the HTML in a UIWebView when your app starts up. (Just a few lines of code.) Do not try to squeeze it into an alert.
You are not allowed to "exit" the application. You may wish to present the EULA in a webview with "Accept" and "Decline" options in a toolbar or as buttons on the webpage. If the user selects "Decline", then you may pop an alert asking then to delete the app from their device. The idea is they can scroll around the webview, but not continue until they hit accept.
I'm not sure if Apple will allow this, it will certainly frustrate your end users.
对于第二个问题:是的,苹果不想退出该应用程序。但是你可以做些什么来强制用户自己退出应用程序:只需显示一个空白屏幕。但我不确定苹果是否会允许这样做,因为它可能被视为“没有功能”。
for problem number two: yes Apple does not want to quit the app. But what you can do to force the user to quit the app on his own: simply show a blank screen. But I'm not sure if Apple would even this allow because it could be seen as "no functionality".