Behdad Ahmadi Behdad Ahmadi - 1 month ago 30
Swift Question

UIActivityController to share URL file

I want to share an URL file that has been created in the app and a text. But it seems it only can share text and not any data like URL or

The code I am using:

let sharedVideo = Video(Title: _data[1], VideoID: _data[0], Duration: _data[3], ViewCount: _data[2])
let sharedURL = VideoManager.exportData(video: sharedVideo)
let shareItems:Array = [sharedURL,"check this out baby!"] as [Any]

let activityViewController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)

self.present(activityViewController, animated: true, completion: nil)

Also I use an
object instead of sharedURL to see If it has problem with URL or not.

It doesn't work even with an image file. When I click on share button inside
, It works just for text, no URL nor image.
I am using Swift 3 in Xcode 8.


PS: I am sure about sharedURL object that it isn't nil nor undefined.


Try this i hope it would be helpful for you!!!

 @IBAction func btnExport(sender: AnyObject)

     let someText:String = "Hello want to share text also"
    let objectsToShare:URL = URL(string: "")!
    let sharedObjects:[AnyObject] = [objectsToShare as AnyObject,someText as AnyObject]
    let activityViewController = UIActivityViewController(activityItems : sharedObjects, applicationActivities: nil)
    activityViewController.popoverPresentationController?.sourceView = self.view

    activityViewController.excludedActivityTypes = [ UIActivityType.airDrop, UIActivityType.postToFacebook,UIActivityType.postToTwitter,UIActivityType.mail]

    self.present(activityViewController, animated: true, completion: nil)