当我 select "Print" 菜单并取消它时,UIActivityViewController.completionWithItemsHandler 不会在 iOS 10.0 上调用

UIActivityViewController.completionWithItemsHandler is not called on iOS 10.0 when I select "Print" menu and cancel it

我创建了一个使用 UIActivityViewController 的简单应用程序,如下所示。

    let text = "Test Text"
    let printData = UISimpleTextPrintFormatter(text: text)
    let vc = UIActivityViewController(activityItems: [text, printData], applicationActivities: nil)
    vc.completionWithItemsHandler = { (type,completed,items,error) in
        print("completed. type=\(type) completed=\(completed) items=\(items) error=\(error)")
    }

    vc.modalPresentationStyle = .popover
    vc.popoverPresentationController?.sourceView = self.openActivityButton
    vc.popoverPresentationController?.sourceRect = self.openActivityButton.bounds
    vc.popoverPresentationController?.permittedArrowDirections = .up
    vc.popoverPresentationController?.delegate = self

    self.present(vc, animated: true) { () in
    }

我 运行 这个应用程序在 iOS 10 (Xcode 8.0 beta 6).

这种奇怪的行为发生在 iOS 10 但没有发生在 iOS9(处理程序在 iOS9 被调用)

这是 iOS 10 的错误吗?如果是这样,是否有任何变通方法来检测 UIActivityController 被关闭?

我在 https://github.com/kunichiko/ios10-activity-bug

上推送了这个示例应用

我遇到了类似的问题。在我的例子中,我注意到没有调用完成处理程序,因为 UIActivityController 已经被解除和释放。我所做的只是添加一个 属性 来保存强引用并稍后将其设置为 nil 。然后正确调用完成处理程序。