UIActivityController共享URL文件

时间:2016-10-22 11:04:26

标签: ios swift swift3 xcode8 uiactivityviewcontroller

我想分享在应用中创建的网址文件和文字。但它似乎只能共享文本而不是URL或UIImage之类的任何数据。 我正在使用的代码:

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)

此外,我使用UIImage对象而不是sharedURL来查看是否存在URL问题。

即使使用图像文件也不起作用。当我点击UIActivityViewController中的分享按钮时,它仅适用于文本,无URL或图像。 我在 Xcode 8 中使用 Swift 3

感谢。

PS:我确定sharedURL对象它不是没有定义的。

1 个答案:

答案 0 :(得分:9)

试试这个:

 @IBAction func btnExport(sender: AnyObject)
{

     let someText:String = "Hello want to share text also"
    let objectsToShare:URL = URL(string: "http://www.google.com")!
    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)

}