how to use web url image in activity controller to share image in swift

389 Views Asked by At

I'm using 'AlamofireImage' pod and show images in collection View cell but client want to share Image I'm using this but not working :

var shareImages = [UIImage]()
    shareImages = [UIImage(named: "http://idea-factory.in/images/25-021.jpg")] as! [UIImage];
                    let activityViewController:UIActivityViewController = UIActivityViewController(activityItems:  shareImages, applicationActivities: nil)
                    let excludedTypes: [UIActivity.ActivityType] = [.postToVimeo, .postToTwitter, .assignToContact, .saveToCameraRoll]
                    activityViewController.excludedActivityTypes = excludedTypes
                    self.present(activityViewController, animated: true, completion: nil)

error comes : Thread 1: signal SIGABRT

2

There are 2 best solutions below

1
Toby Clark On

I'm not sure if this is helpful but I normally get that error if I either haven't linked up my view controllers properly or needed to force unwrap a value and haven't.

0
Talha Ahmad Khan On

You must use the image once it is received completely. One of the methods you can use is

let downloader = ImageDownloader()
let urlRequest = URLRequest(url: URL(string: "http://idea-factory.in/images/25-021.jpg")!)

    downloader.download(urlRequest) { response in
        print(response.request)
        print(response.response)
        debugPrint(response.result)

        if let image = response.result.value {
            //use your activity  controller here
        }
    }