CNContactViewController forUnknownContact无法使用,破坏了界面

mat*_*att 29 ios9 cncontact

[似乎在iOS 10中修复!]因此以下内容仅适用于iOS 9 ...


我一直在试验Apple新的Contacts框架,我发现CNContactViewController的三种形式之一存在一个巨大的错误.它破坏了周围的界面,使你的应用变得无用; 用户卡住了.

为了使这个bug易于查看,我在https://github.com/mattneub/CNContactViewControllerBug上发布了一个示例项目.

要进行实验,请运行该项目并执行以下步骤:

  1. 点击按钮(未知人员).

  2. 如果请求,授予访问权

  3. 您将在我们的导航界面中显示部分联系人(请注意顶部的"返回"按钮).

  4. 点按添加到现有联系人.出现联系人选择器.

  5. 点按取消.实际上你从这里做什么并不重要,但点击取消是最简单的,也是达到错误的最快方法.

  6. 我们现在回到部分联系,但导航界面已经消失.用户无法从此界面中退出.该应用程序被软管.

只是为了澄清,以下是您需要采取的步骤的屏幕截图:

在此输入图像描述

点按添加到现有联系人即可查看:

在此输入图像描述

点按取消即可看到此内容; 观察它与第一个屏幕截图相同,但导航栏消失了:

在此输入图像描述

我已经尝试了很多方法来解决这个bug,但似乎没办法.据我所知,此窗口由"进程外"框架呈现,不属于您的应用程序.你无法摆脱它.

那么问题是什么?我猜是这样的:任何人都可以告诉我一种方法来使这个视图控制器(在这种形式下)可用吗?有没有找到的解决方法?

编辑此错误出现在iOS 9.0中,仍然存在于iOS 9.1中.在评论中,@ ServgeSkopus报告说切换到已弃用的通讯簿框架没有帮助; bug在某处的底层结构中.

Gia*_*mmy 8

我隐藏了UINavigationController方法,用于通过使用类别来显示或隐藏导航栏:

@interface UINavigationController (contacts)
@end

@implementation UINavigationController (contacts)

- (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated {
    NSLog(@"Hide: %d", hidden);
}
@end
Run Code Online (Sandbox Code Playgroud)

这样CNContactViewController无法使导航栏消失.在NSLog上设置断点我发现这个方法是私有的[CNContactViewController isPresentingFullscreen:].

通过检查self.topViewController导航控制器的类型是否类,CNContactViewController您可以决定是否隐藏导航栏.


mat*_*att 7

显然这是一个错误,因为Apple最终通过声明重复来回复我的错误报告.

  • @mattt你可以请分享该报告错误的链接 (2认同)

小智 5

我发现使“CNContactViewController forUnknownContact”可用的唯一方法是放弃导航栏并使用工具栏退出这样的模式视图(在目标C中):

CNContactViewController *picker = [CNContactViewController viewControllerForUnknownContact: newContact];
picker.delegate = self;

UINavigationController *newNavigationController = [[UINavigationController alloc] initWithRootViewController:picker];

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStyleDone target:self action:@selector(YourDismissFunction)];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[picker setToolbarItems:[[NSArray alloc] initWithObjects:flexibleSpace, doneButton, flexibleSpace, nil] animated:NO];

newNavigationController.toolbarHidden = NO;
picker.edgesForExtendedLayout = UIRectEdgeNone;

[self presentViewController:newNavigationController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

希望它可以帮助