我在不同的社交媒体上使用UIActivityViewController
分享图片,视频和LivePhoto。
但是当我在 WhatsApp 上分享 LivePhoto 时,会出现以下情况:
ActivityViewController
完成处理程序打印错误时,它打印出类似这样的内容:[core] SLComposeViewController remoteViewController: didTerminateWithError: 错误域= _UIViewServiceInterfaceErrorDomain Code = 3“(null)” UserInfo = {Message =服务连接中断} [核心] SLComposeViewController completeWithResult:0 [核心] SLComposeViewController跳过显式解雇因为 isBeingDismissed已经是1个SLComposeViewController dealloc
I have tried with this code :
PHImageManager.default().requestImageData(for: selectedAsset, options: nil, resultHandler: { (imgData, str, image, info) in
activityItems.append(imgData!)
let activityViewController = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
activityViewController.completionWithItemsHandler = {(activityType: UIActivityType?, completed: Bool, returnedItems:[Any]?, error: Error?) in
//Do whatever you want
print("activityType ----- \(activityType) || error ----- \(error)")
}
// present the view controller
DispatchQueue.main.async {
// self.present(activityViewController, animated: true, completion: nil)
self.navigationController?.present(activityViewController, animated: true, completion: nil)
}
})
任何人都可以帮助我。
谢谢。
答案 0 :(得分:4)
我在这里得到了解决方案
我已删除UIActivityController
和已使用UIDocumentInteractionController
,如下所示:
let imageLocalPath = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("public.jpeg")
if let imageData = imgData {
do {
try imageData.write(to: imageLocalPath, options: .atomic)
self.documentInteractionController = UIDocumentInteractionController(url: imageLocalPath)
// self.documentInteractionController.uti = "net.whatsapp.image"
self.documentInteractionController.uti = "public.image"
self.documentInteractionController.delegate = self
self.documentInteractionController.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)
} catch {
print(error)
}
}
然后在委托方法中:
适用于WhatsApp :
func documentInteractionController(_ controller: UIDocumentInteractionController, willBeginSendingToApplication application: String?) {
print("Application ----- \(String(describing: application))")
if(check for whatsApp condition){
let imageLocalPath = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("whatsAppTmp.wai")
if let imageData = selectedImageData {
do {
try imageData.write(to: imageLocalPath, options: .atomic)
controller.uti = "net.whatsapp.image"
controller.url = imageLocalPath
} catch {
print(error)
}
}
}
}