我试图让我们的 iOS 应用程序在通过 AirDrop 共享文件时仅识别 iOS 设备UIActivityViewController
。这是我用来初始化视图控制器的代码。
var fileUrl = Bundle.main.url(forResource: "myBusinessCard", withExtension: nil)!
let controller = UIActivityViewController(activityItems: ["Sharing File", fileUrl], applicationActivities: nil)
controller.excludedActivityTypes = [UIActivityType.postToFacebook, UIActivityType.postToTwitter, UIActivityType.postToWeibo, UIActivityType.print, UIActivityType.copyToPasteboard, UIActivityType.assignToContact, UIActivityType.saveToCameraRoll, UIActivityType.postToFlickr, UIActivityType.postToTencentWeibo, UIActivityType.mail, UIActivityType.message] // UIActivityType.airDrop
self.present(controller,animated: true, completion: nil)
我已经为我们的文件类型创建了一个新的 UTI,以便正确的应用程序自动打开它。