当打开iTunes App Store网址时,为什么Web视图中的取消按钮不起作用。 (以供理解)

问题描述 投票:-1回答:1

是因为未实现取消按钮方法?

circled in blue cancel button not working

下面是我的代码。通过警报视图通知用户有可用的更新版本。如果单击确定,它将把它们定向到iTunes App Store中的应用程序。 (如下图所示)但是,单击取消时,什么也没有发生。

-(void)showAlert {

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"New Version Available on Appstore" message:@"Please update app to continue" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        UIApplication *application = [UIApplication sharedApplication];
        NSURL *iTunesLink = [NSURL URLWithString:@"itms://itunes.apple.com/us/app/apple-store/id375380948?mt=8"];
        [application openURL:iTunesLink options:@{} completionHandler:^(BOOL success) {
            if (success) {
                 NSLog(@"Opened url");
            }
        }];
            //button click event
                        }];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
    [alert addAction:ok];
    [alert addAction:cancel];
    [self presentViewController:alert animated:YES completion:nil];
}

我设法通过添加“ itms-apps”(直接重定向到应用商店,没有取消按钮)来解决此问题。但是我仍然想了解为什么取消按钮不起作用

由于Web视图中的取消按钮不是我创建的,是否可以向其中添加方法?

我很抱歉在我的问题中不清楚。我想知道为什么截图中带圆圈的取消按钮不起作用。

ios objective-c iphone app-store ios11
1个回答
0
投票

创建UIAlertController时,您可以向其中添加不同的按钮作为UIAlertActions,当每个按钮被单击时它们将执行某些操作。您将必须通过在UIAlertAction的初始化中实现处理程序来指定要发生的事情(就像您在上面的OK操作中所做的那样)。

如果您将nil作为处理程序传递,则警报将被简单地消除,但是不会发生任何其他事情,因为您没有告诉它做任何其他事情。

取消按钮与单击警报按钮有关,与您单击其他按钮后所做的任何操作无关,这可能与您的情况有关。

更多信息here

© www.soinside.com 2019 - 2024. All rights reserved.