我想从共享UIActivity Controller中删除“iCloud drive”选项,这是一个快照。
我尝试了这个,但是它没有在swift 3中工作。
activityViewController.excludedActivityTypes = [.assignToContact,.copyToPasteboard,.print,.saveToCameraRoll,.addToReadingList,UIActivityType(rawValue: "com.apple.reminders.RemindersEditorExtension"),UIActivityType(rawValue: "com.apple.mobilenotes.SharingExtension"),UIActivityType(rawValue: "com.apple.iCloudDrive.ShareExtension"),UIActivityType(rawValue: "com.apple.mobileslideshow.StreamShareService")]
答案 0 :(得分:2)
可能会有所帮助,具体取决于版本:
Apple不断更改此扩展程序的捆绑包ID。您可能还需要排除这一点,但取决于iOS SDK版本:
UIActivityType(rawValue: "com.apple.CloudDocsUI.AddToiCloudDrive")
用户选择后的活动项目提供商:
您还可以将UIActivityItemProvider对象而不是原始对象传递给UIActivityViewController初始化程序。遗憾的是,这不会更改UI中启用的选项,但如果在用户选择后没有返回任何项目,则会退出。
首先,为您的提供者创建一个新类。您可以使用它来返回基于不同提供商的不同内容!即邮件的图像和文本,仅适用于iMessage的文本。
class ShareActivityItemProvider: UIActivityItemProvider {
override func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivityType) -> Any? {
print("activity type selected: \(activityType.rawValue)")
// These are your accepted activity types
if activityType == .postToFacebook || activityType == .postToTwitter || activityType == .postToWeibo || activityType == .mail || activityType == .message {
return placeholderItem
}
return nil
}
}
然后你就像这样初始化你的UIActivityItemProvider:
let avc = UIActivityViewController(activityItems: [ShareActivityItemProvider(placeholderItem: "Test message or any object")], applicationActivities: nil)
或者,做你想做的事情的hacky但合法的方式:
在上面之后,你可以添加一个占位符空的UIImage,删除现在可用的其他选项,只返回你想要的提供者:
let avc = UIActivityViewController(activityItems: [ShareActivityItemProvider(placeholderItem: "Test message or any object"), ShareActivityItemProvider(placeholderItem: UIImage())], applicationActivities: nil)
avc.excludedActivityTypes = [.assignToContact,.saveToCameraRoll,...其他......]
class ShareActivityItemProvider: UIActivityItemProvider {
override func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivityType) -> Any? {
print("activity type \(activityType.rawValue) \(activityType)")
if placeholderItem is String, activityType == .postToFacebook || activityType == .postToTwitter || activityType == .postToWeibo || activityType == .mail || activityType == .message {
return placeholderItem
}
return nil
}
}