无法取消 UIActivityViewController 或 UIAlertController

UIActivityViewController or UIAlertController cannot be cancelled

我正在尝试使用 UIActivityViewController 分享 URL,如下所示。这很好,但不能取消,即点击取消按钮什么都不做。这仅在我的应用程序中。如果我创建一个带有嵌入导航控制器的视图控制器的测试应用程序,它可以正常工作。我的应用程序有一个带有导航控制器的选项卡栏控制器,我试图从中展示它的视图控制器位于第三个选项卡上,并且是当前的顶视图控制器。

NSString *string =  @"Check this site out";
NSURL *URL = [NSURL URLWithString:@"www.apple.com"];

self.activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[string, URL] applicationActivities:nil];          

[self.navigationController presentViewController:self.activityViewController animated:YES completion:nil];

我也尝试过将它显示的控制器更改为选项卡栏控制器和 keyWindow 的根视图控制器,但没有成功。

我什至尝试添加一个完成处理程序,如下所示,但它甚至没有被调用!

__weak typeof(self) weakSelf = self;

[self.activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed) {

    [weakSelf dismissViewControllerAnimated:YES completion:nil];
}];

不确定如何进行...欢迎提出任何建议。

更新:

有趣的是,我发现我也无法 cancel/dismiss UIAlertController...即使使用这个基本的 Apple 示例也是如此。

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert"  message:@"This is an alert." preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {}];

[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];

好的,事实证明这些控制器总是从根视图控制器呈现。我正在使用的应用程序有一个覆盖 dismissViewController:animated: 并且没有调用 super 的根视图控制器。