我希望将AirDrop作为我应用程序中唯一的选项带出共享表。
在iOS 7中,我可以简单地将所有共享类型添加到excludedActivityTypes
的{{1}}属性中UIActivityViewController
,UIActivityTypeMessage
,...)
但是现在在iOS 8中,通过应用扩展程序,用户可能会有额外的共享提供程序显示出来。 有没有办法只显示AirDrop ?
UIActivityTypeMail
答案 0 :(得分:2)
class AirDropOnlyActivityItemSource : NSObject, UIActivityItemSource {
/// The item you want to send via AirDrop.
let item: AnyObject
init(item: AnyObject) {
self.item = item
}
func activityViewControllerPlaceholderItem(activityViewController: UIActivityViewController) -> AnyObject {
/// Use an empty URL as placeholder to let iOS Share Sheet show the AirDrop only.
return NSURL(string: "")!
}
func activityViewController(activityViewController: UIActivityViewController, itemForActivityType activityType: String) -> AnyObject? {
return item
}
}
答案 1 :(得分:1)
Jonny's answer的Swift 4.2版本:
class AirDropOnlyActivityItemSource: NSObject, UIActivityItemSource {
///The item you want to send via AirDrop.
let item: Any
init(item: Any) {
self.item = item
}
func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
//using NSURL here, since URL with an empty string would crash
return NSURL(string: "")!
}
func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
return item
}
}
用法:
let itemSource = AirDropOnlyActivityItemSource(item: "test")
let activityVc = UIActivityViewController(activityItems: [itemSource], applicationActivities: nil)
答案 2 :(得分:0)
目前无法做到这一点。您应该提交enhancement request with apple来解释为什么这对用户/开发人员有用。