Sharing Live photo on WhatsApp in Swift 3 using UIActivityViewController not working
Asked Answered
I

1

7

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 :

  1. when ActivityViewController present -> click on WhatsApp -> it present contact list for second and quickly dismiss and when i try to print error using 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.

Icao answered 13/7, 2017 at 11:57 Comment(9)
Sounds like WhatsApp doesn't support live photos. Can you share it somewhere else, like iMessage? If it works everywhere else, it's probably WhatsApp that doesn't support it.Allomorphism
can you show your tried codeUntouchable
@EmilioPelaez, If Whatsapp doesn't support live photo then, when I share still image from live photo it shows random errors sometimes like above and sometimes like "This item cannot be shared, Please select different item"Icao
@Untouchable : i have added code aboveIcao
image data is nsdata or elseUntouchable
@Untouchable : yes NSDataIcao
see this for example #36165722 or append the image see this #20417547,Untouchable
but your data is high , so connection InterruptedUntouchable
@Untouchable : refered your given link but this for specific whatsApp but i need to share my photos and Live photos on each social media which are given in UIActivityViewController so this is not useful for me.Icao
I
4

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)
            }
        }
    }
 }
Icao answered 14/7, 2017 at 9:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.