Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent my own app's share extension from appearing in the share sheet

I'm building an iOS app that manages audio files. It includes a share extension to receive audio files from other apps. It also can share its audio files with other apps.

When a share is initiated from my app, I do not want my own app to appear in the share sheet. In other words, I do not want the user to send my own audio file back to my app.

I cannot find a way to exclude my own app with an NSExtensionActivationRule.

like image 928
Steve s. Avatar asked Nov 08 '22 18:11

Steve s.


1 Answers

First of all define below lines in your code:

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

Here com.your.unique.uti is your Application group identifier:

see this image for refrence

and then while presenting activityViewController use code below:

let activityViewController = UIActivityViewController(activityItems: [/* Other Items To Share, */ ActionExtensionBlockerItem()], applicationActivities: nil)
like image 148
singh.jitendra Avatar answered Nov 15 '22 12:11

singh.jitendra