I am trying to get my SwiftUI app to be listed on the share sheet of IOS photo library, so the user can directly open the application with this image.
Example: Apps like facebook, WhatsApp and Instagram do show up on the share sheet and I want my app to be on that list as well.
I was successful on showing my app on the share sheet of an image when opened from the "Files" but not working on the Photos Library.
I have added these lines of code in my app's Info.plist
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>myapp image</string>
</array>
<key>CFBundleTypeName</key>
<string>imageData</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.png</string>
<string>public.jpeg</string>
<string>public.heic</string>
</array>
</dict>
</array>
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.image</string>
</array>
<key>UTTypeDescription</key>
<string>PNG image</string>
<key>UTTypeIconFiles</key>
<array/>
<key>UTTypeIdentifier</key>
<string>public.png</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>png</string>
</array>
</dict>
</dict>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.image</string>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>JPEG image</string>
<key>UTTypeIconFile</key>
<string>public.jpeg.icns</string>
<key>UTTypeIconFiles</key>
<array/>
<key>UTTypeIdentifier</key>
<string>public.jpeg</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>jpeg</string>
<string>jpg</string>
</array>
</dict>
</dict>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.image</string>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>HEIC image</string>
<key>UTTypeIconFiles</key>
<array/>
<key>UTTypeIdentifier</key>
<string>public.heif-standard</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>heic</string>
</array>
</dict>
</dict>
</array>
To get your SwiftUI app to show up in the iOS Photos share sheet, you will need to do the following:
Add the "Photos" entitlement to your app's entitlements file. This will allow your app to access the user's photo library.
Implement the UIActivityViewController class in your app. This class provides a standard interface for sharing content with other apps, including the Photos app.
In your SwiftUI view, add a button or other control that will trigger the share sheet. When the user taps this control, present an instance of UIActivityViewController modally.
In the initializer for UIActivityViewController, set the activityItems parameter to an array of the items you want to share (e.g. a UIImage or URL object).
In the initializer for UIActivityViewController, set the applicationActivities parameter to an array of custom UIActivity objects, if you want to include custom actions in the share sheet.
Present the UIActivityViewController modally when the user taps the share button.
}