gpt4 book ai didi

ios - 如何从 UIActivity Controller 中删除 "Add to iCloud Drive"?

转载 作者:搜寻专家 更新时间:2023-10-31 22:41:53 24 4
gpt4 key购买 nike

我想从共享 UIActivity Controller 中删除“iCloud 驱动器”选项,这是一个快照。

enter image description here

我试过了,但它在 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")]

最佳答案

可能会有所帮助,具体取决于版本:

Apple 不断更改此扩展程序的包 ID。您可能也需要排除它,但这取决于 iOS SDK 版本:

UIActivityType(rawValue: "com.apple.CloudDocsUI.AddToiCloudDrive")

用户选择后的事件项目提供者:

您还可以将 UIActivityItemProvider 对象而不是原始对象传递给 UIActivityViewController 初始化程序。不幸的是,这不会更改 UI 中启用的选项,但如果在用户选择后没有返回任何项目,则会退出。

首先,为您的提供商创建一个新类。您也可以使用它来返回基于不同提供商的不同内容! IE。用于邮件的图像和文本,仅用于 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)

或者,做你想做的事的骇人听闻但合法的方式:

在上面之后,您可以添加一个空的 UIImage 占位符,删除现在可用的其他选项,并且只返回您想要从提供者那里得到的内容:

let avc = UIActivityViewController(activityItems: [ShareActivityItemProvider(placeholderItem: "Test message or any object"), ShareActivityItemProvider(placeholderItem: UIImage())], applicationActivities: nil)
avc.excludedActivityTypes = [.assignToContact, .saveToCameraRoll, ... others ...]

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
}
}

关于ios - 如何从 UIActivity Controller 中删除 "Add to iCloud Drive"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44898479/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com