Search code examples
iosswiftslcomposeviewcontroller

Swift - SLComposeViewController automatically dismissing itself


I am using SLComposeViewController for social sharing of photos.But i am getting this error in log

SLComposeViewController automatically dismissing itself

My code:-

@IBAction func fbshare(_ sender:UIButton) {
    let vc = SLComposeViewController(forServiceType:SLServiceTypeFacebook)
    vc?.add(img.image!)
    vc?.add(URL(string: "http://www.example.com/"))
    vc?.setInitialText("Initial text here.")
    self.present(vc!, animated: true, completion: nil)
}

I am not able to get the SLComposeViewController on my screen.


Solution

  • This is working and for SLServiceTypeFacebook too but need to dismiss one to present the other. I am still working that out.

    if let vc = SLComposeViewController(forServiceType: SLServiceTypeTwitter) {
    
            //SLServiceTypeFacebook
            //SLServiceTypeTwitter
    
            vc.setInitialText(self.writeDBString)
            //vc.add(UIImage(named: "myImage.jpg")!)
            vc.add(URL(string: "https://itunes.apple.com/us/app"))
            present(vc, animated: true )            
    }