首次启动应用程序时 iPhone 通知

发布于 2024-10-12 08:04:53 字数 1499 浏览 5 评论 0原文

我希望用户在启动应用程序之前接受协议。因此,在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

别把无礼当个性 2024-10-19 08:04:53

是的,如果您强制退出,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

盗琴音 2024-10-19 08:04:53

我已经成功地使用此委​​托方法:

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex

并确保您的应用程序使用alertView 的cancelButtonIndex 和firstOtherButtonIndex 属性,以便您处理正确的按钮;我认为取消按钮目前通常索引为零,但这可能会改变。

I have had success using this delegate method instead:

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex

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.

酸甜透明夹心 2024-10-19 08:04:53

处理 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.

梦开始←不甜 2024-10-19 08:04:53

对于第二个问题:是的,苹果不想退出该应用程序。但是你可以做些什么来强制用户自己退出应用程序:只需显示一个空白屏幕。但我不确定苹果是否会允许这样做,因为它可能被视为“没有功能”。

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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文