How to Add My App to the Share Sheet Action

Adding an open In option to the share sheet in ObjectiveC

The "Open in…" options are made available based on the content that's being opened and the document types supported by the device's installed apps. It's not something you can alter from your app.

On the other hand, if the apps that you want to appear in your app's "Open in" list are other apps you have control over, then you can add CFBundleDocumentTypes keys to those apps' info.plists. This tells iOS that the apps can open certain types of files. You specify supported filetypes using UTIs like public.jpeg and so on, and when a user tries to open one of those file types from a UIActivityViewController, ios will include the supporting applications in the options.

Here's a good discussion of that: How do I get my application to show up in the Open in... menu

And here's a discussion on UTIs: Uniform Type Identifier Concepts

So, for example, if one of your apps supported opening jpeg images and any text file, you would add this to the info.plist:

<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>Images</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.jpeg</string>
</array>
</dict>
<dict>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>text</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.plain-text</string>
</array>
</dict>
</array>

But, again, if you're trying to manipulate the apps that are shown as "Open in" options from the app displaying the activity controller, you can't. You can only make your own apps advertise that they support certain document types, and from that iOS builds up its "Open in" options.

How to add extra options to iOS Share Sheet like Safari does

When you initialise a share sheet (aka UIActivityController), you are asked for an array of applicationActivities, that is where your custom internal/share actions will go.

You should just subclass UIActivity, and override the required members as specified by the documentation:

  • activityType
  • activityTitle
  • activityImage
  • canPerform(withActivityItems:)
  • prepare(withActivityItems:)
  • activityCategory

To make your UIActivity appear as a menu button at the bottom of the share sheet, make sure you return .action for activityCategory. If you return .share, it will appear as a square button at the top.

Example:

// dummy implementation
class Foo: UIActivity {
override var activityTitle: String? { "Foo" }
override var activityType: UIActivity.ActivityType? { UIActivity.ActivityType("Foo") }
override var activityImage: UIImage? { UIImage(systemName: "doc.on.doc.fill") }
override func canPerform(withActivityItems activityItems: [Any]) -> Bool {
true
}
override class var activityCategory: UIActivity.Category { .action }
override func prepare(withActivityItems activityItems: [Any]) {
print("Preparing Foo!")
}
override func perform() {
print("Performed Foo!")
}
}

...

let shareSheet = UIActivityViewController(activityItems: [stuffToShare], applicationActivities: [Foo()])

Output:

Sample Image

If I use .share instead:

Sample Image

My app is not showing up in Share Sheet

There was mistake in My Plist file that's why was facing such issue.

Posting this answer just because may be in future if someone will do such mistake so my answer could help out!

<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsText</key>
<true/>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>1</integer>
</dict>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
</dict>

This is working perfectly fine!

Swift Remove app from the share sheet action

let activityViewController = UIActivityViewController(activityItems: items,
applicationActivities: nil)

activityViewController.excludedActivityTypes = UIActivity.ActivityType.postToFacebook


Related Topics



Leave a reply



Submit