5

我希望能够使用 UIActivityViewController 同时空投文本文件和图像。下面的代码可以很好地通过 iMessage 或电子邮件发送两种文件类型,但是当我尝试使用 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)
}
4

1 回答 1

1

AirDrop 到 iOS 设备不支持发送多种不同类型,但发送到 mac 可以。在 Apple 更改之前,您无法更改任何代码来“修复”此问题。

于 2016-12-31T20:58:15.800 回答