83djxa
Last Updated: February 25, 2016
·
2.094K
· supremegravity
8e97d3418e72e86212ebcdd6fd3bc9d5

Registering your app to be able to open images from other apps

Picture

To your app to the globally available 'Open with...' dialogue that other apps use you need to:

  1. Register your app as handling types of files (e.g. images, pdfs, etc.)
  2. Implement a method that gets called in your app when another app passes a file to you

For images:

1. Register your app as accepting images by adding data to the plist file.

Add CFBundleDocumentTypes to your plist (in the Rakefile):

app.info_plist['CFBundleDocumentTypes'] = [{
    "CFBundleTypeExtensions" => ["pdf"],
    "CFBundleTypeName" => "public.pdf",
    "CFBundleTypeIconFile" => "app.icns",
    "LSItemContentTypes" => ["public.pdf"],
    "CFBundleTypeRole" => "Editor", #or Viewer
    "LSHandlerRank" => "Alternate"
},
{"CFBundleTypeExtensions" => ["png"],
"CFBundleTypeName" => "public.png",
"CFBundleTypeIconFile" => "app.icns",
"LSItemContentTypes" => ["public.png"],
"CFBundleTypeRole" => "Editor", #or Viewer
"LSHandlerRank" => "Alternate"
}]

Add UTImportedTypeDeclarations to your plist (in the Rakefile):

    app.info_plist['UTImportedTypeDeclarations'] = [{
        "UTTypeConformsTo" => ["public.data"],
        "UTTypeIdentifier" => "public.pdf",
        "UTTypeTagSpecification" => {
            "com.apple.ostype" => "PDF",
            "public.mime-type" => "application\/pdf",
            "public.filename-extension" => ["pdf"]
        }}, {
        "UTTypeConformsTo" => ["public.image"],
        "UTTypeIdentifier" => "public.png",
        "UTTypeTagSpecification" => {
            "com.apple.ostype" => "PNG",
            "public.mime-type" => "image\/png",
            "public.filename-extension" => ["png"]
        }
    }]
end

More about this step here: From Registering Your Support of File Types

2. Implement application:openURL:sourceApplication:annotation: in your app_delegate

This method is called whether or not your app is already open. (If your app isn't open, application:didFinishLaunchingWithOptions: is called first.)

This gets called when another app sends a file to your app

def application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
   #url.nsdata => data of the file passed
   #e.g. open a new view controller
   foo = MyImageManipulatorViewController.alloc.initWithURL(url)
   # ...
   true
 end

More about this step here: Opening Supported File Types


Note You can't add your app to the list of share options the native Photos and Camera Roll apps use.


See also

Overview of sharing/opening docs across apps:
About Document Interaction

Other document types:
CFBundleDocumentTypes

1 Response
Add your response

22288
0 0qblxt rb1w0lt0y1c1llbbrq1p0l1ghrc10sq9arlgylial1qxrbrcrt1dc  m2vcarcvskzk o biy1zcsbvhyjk x cey1zctynzl95n143lhxkqpphr8gam7ucjssn6grepprgv

Hi,
I have implemented as given, but my application is not showing.

over 1 year ago ·