Registering your app to be able to open images from other apps
To your app to the globally available 'Open with...' dialogue that other apps use you need to:
- Register your app as handling types of files (e.g. images, pdfs, etc.)
- 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
Written by spnkr
Related protips
2 Responses
Hi,
I have implemented as given, but my application is not showing.
How do I register my appo handle map navigation requests from a third party app?