I am sharing Image,video and LivePhoto using UIActivityViewController
on Different social media.
But when i am sharing LivePhoto on WhatsApp ,something like below is happening :
ActivityViewController
Completion handler it print something like this : [core] SLComposeViewController remoteViewController: didTerminateWithError: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo={Message=Service Connection Interrupted} [core] SLComposeViewController completeWithResult: 0 [core] SLComposeViewController skipping explicit dismiss because isBeingDismissed is already 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)
}
})
can anyone help me with please.
Thank you.
Here I got the solution
I have removed UIActivityController
and Used UIDocumentInteractionController
like below :
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)
}
}
Then In delegate method of it :
For 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)
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With