7

UIActivityViewController在不同的社交媒体上分享图像、视频和 LivePhoto。

但是当我在WhatsApp上分享LivePhoto时,会发生以下情况:

  1. 当 ActivityViewController 存在时 -> 单击 WhatsApp -> 它显示第二个联系人列表并快速关闭,当我尝试使用ActivityViewControllerCompletion 处理程序打印错误时,它会打印如下内容:

[核心] SLComposeViewController remoteViewController: didTerminateWithError: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo={Message=Service Connection Interrupted} [核心] 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)

                }
            })

谁能帮帮我。

谢谢你。

4

1 回答 1

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)
            }
        }
    }
 }
于 2017-07-14T09:41:37.137 回答