UIActivityViewController - 无法同时AirDrop多个对象类型

时间:2016-12-31 20:32:06

标签: swift uiactivityviewcontroller airdrop

我希望能够使用UIActivityViewController同时AirDrop文本文件和图像。下面的代码可以通过iMe​​ssage或eMail发送两种文件类型,但是当我尝试使用AirDrop时它失败了。该代码适用于AirDropping 2图像或2个文本文件,但不适用于每个图像。

@IBAction func shareImage(_ sender: UIButton)
{
    // can't seem to AirDrop a mixture of file types. ie. can send 2 images, or 2 data files, but not an image and a data file
    let fileToSend: NSURL = NSURL(fileURLWithPath: dataFile!)
    let image = imageView.image!
    let objectsToShare = [fileToSend, image] as [Any]
    let controller = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)

    controller.excludedActivityTypes = [UIActivityType.postToFacebook, UIActivityType.postToTwitter, UIActivityType.postToWeibo, UIActivityType.print, UIActivityType.copyToPasteboard, UIActivityType.assignToContact, UIActivityType.saveToCameraRoll, UIActivityType.postToFlickr, UIActivityType.postToTencentWeibo]
    self.present(controller, animated: true, completion: nil)
}

1 个答案:

答案 0 :(得分:1)

AirDrop到iOS设备不支持发送多种不同类型,但发送到mac的确如此。在Apple改变之前,没有代码更改,你可以做"修复"这个。