11

I created a simple application which uses UIActivityViewController as below.

    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
    }

and I run this application on iOS 10 (Xcode 8.0 beta 6).

  • When I close activity dialog, the completionWithItemsHandler is called.
  • When I select "Copy" activity, the completionWithItemsHandler is called.
  • When I select "Mail" activity and cancel it, the completionWithItemsHandler is called.
  • But, when I select "Print" activity and cancel it, the completionWithItemsHandler is not called.

This strange behavior occurred on iOS 10 but not occurred on iOS9 (the handler was called on iOS9)

Is this iOS 10's bug? If so, are there any workarounds to detect the UIActivityController is dismissed?

I pushed this sample app on https://github.com/kunichiko/ios10-activity-bug

kunichiko
  • 113
  • 1
  • 7

1 Answers1

11

I had a similar problem. In my case, I noticed that the completion handler was not called because the UIActivityController was already dismissed and deallocated. What I did was just add a property to hold a strong reference and set it to nil later. Then the completion handler was called properly.

juf
  • 204
  • 3
  • 6