I'm using iOS 12 and Facebook SDK 13.2.0 to share texts and links in Facebook using UIActivityViewController this way:
var items: [Any] = [model?.shareInfo?.text ?? NSLocalizedString("shareMessage", comment: "")]
if let urlString = model?.shareInfo?.url, let url = URL(string: urlString) {
items.append(url)
}
let ac = UIActivityViewController(activityItems: items, applicationActivities: nil)
present(ac, animated: true)
This is working well and the app shares in Facebook without problems. But I'm having 2 problems that I don't know how to solve:
The user selects Facebook in the sharing sheet > The Facebook sharing view appears > The user cancels > A UIActionSheet appears from the bottom of the screen asking to discard or keep the post > The user clicks on Discard > The UIActionSheet dissappears but the Facebook sharing view keeps showing, there's no way to go back.
The user selects Facebook in the sharing sheet > The Facebook sharing view appears > The user clicks on Next > another Facebook sharing view appears > The user shares the content > The content is shared in Facebook and a black screen shows a check icon and a "Shared on Facebook" message > this black screen cannot be closed anyway, it has no buttons.
To detect these cases I modified my code to this:
let ac = UIActivityViewController(activityItems: items, applicationActivities: nil)
ac.completionWithItemsHandler = { (activityType: UIActivity.ActivityType?, completed: Bool, arrayReturnedItems: [Any]?, error: Error?) in
if completed {
print("share completed")
return
} else {
print("cancel")
}
if let shareError = error {
print("error while sharing: \(shareError.localizedDescription)")
}
}
present(ac, animated: true)
But sharing to facebook doesn't show any log, this completion handler is not called. On the other hand, if I share to email or any other app, these callbacks are in fact called, so the completionWithItemsHandler is working well, the problem is only with Facebook and how it's managing the sharing views.
Any clue on how to close the Facebook sharing views on canceling and after success?