UIActivityViewController隐藏我的应用程序共享扩展

时间:2018-01-16 15:11:07

标签: ios swift3 uiactivityviewcontroller ios-sharesheet

在我的应用程序中,我添加了我的共享扩展程序,它工作正常,但我遇到一个问题当我通过UIActivityViewController邀请应用程序时,我显示了我的应用程序扩展。如何隐藏我的应用程序扩展我自己的应用程序?

2 个答案:

答案 0 :(得分:0)

您可以通过在list of excluded activity types

中添加扩展活动类型来实现
let activityViewController = UIActivityViewController(activityItems: <your items>, applicationActivities: <your supported application activities>)

let extensionActivityType = UIActivityType(<your extension activity type id>)
activityViewController.excludedActivityTypes = [extensionActivityType]

答案 1 :(得分:0)

很抱歉,但是希望这个回答能对您有所帮助。

首先在代码中定义以下行

class ActionExtensionBlockerItem: NSObject, UIActivityItemSource {
func activityViewController(_ activityViewController: UIActivityViewController, dataTypeIdentifierForActivityType activityType: UIActivityType?) -> String {
    return "com.your.unique.uti";
}
func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivityType) -> Any? {
    // Returning an NSObject here is safest, because otherwise it is possible for the activity item to actually be shared!
    return NSObject()
}
func activityViewController(_ activityViewController: UIActivityViewController, subjectForActivityType activityType: UIActivityType?) -> String {
    return ""
}
func activityViewController(_ activityViewController: UIActivityViewController, thumbnailImageForActivityType activityType: UIActivityType?, suggestedSize size: CGSize) -> UIImage? {
    return nil
}
func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
    return ""
}

}

com.your.unique.uti 是您的应用程序组标识符see this image for refrence 然后在显示activityViewController时使用下面的代码

let activityViewController = UIActivityViewController(activityItems: [/* Other Items To Share, */ ActionExtensionBlockerItem()], applicationActivities: nil)