Adding "Open In..." option to iOS app
Solution 1:
Take a look at the Document Interaction Programming Topics for iOS: Registering the File Types Your App Supports.
As long as you provide your document types in your Info.plist, other apps that recognize that document type will list your app in their "open in" choices. Of course, that presumes that your app creates documents that other apps can open.
Solution 2:
This is a great tutorial, that helped me.
I have added support for *.xdxf
files in my app. In short, you have to do two things. First - add entries like this to your app's Plist
file:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>XDXF Document</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSItemContentTypes</key>
<array>
<string>com.alwawee.xdxf</string>
</array>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeDescription</key>
<string>XDXF - XML Dictionary eXchange Format</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.text</string>
</array>
<key>UTTypeIdentifier</key>
<string>com.alwawee.xdxf</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<string>xdxf</string>
<key>public.mime-type</key>
<string>text/xml</string>
</dict>
</dict>
</array>
Here, you should add UTExportedTypeDeclarations
only if your file type is unique. Or by other words is not here.
Second - handle delegate method in AppDelegate
:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
if (url != nil && [url isFileURL]) {
// xdxf file type handling
if ([[url pathExtension] isEqualToString:@"xdxf"]) {
NSLog(@"URL:%@", [url absoluteString]);
}
}
return YES;
}
Solution 3:
In order to be visible in the list of "open in..." for all files, you need to add this to your plist
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>Open All Files</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSItemContentTypes</key>
<array>
<string>public.content</string>
<string>public.data</string>
</array>
</dict>
</array>
Once your app shows in "open in...", you need to load that file. Most website shows to implement this function:
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject?) -> Bool
{
println("Open URL "+url.path!)
}
But this function that worked fine in IOS 7 crashes in IOS 8. I had to implement the following function instead to get it to work.
func application(application: UIApplication, handleOpenURL url: NSURL) -> Bool
{
println("Open URL "+url.path!)
}
Solution 4:
I add my app in "open in" list successfully as follows,
Add a new document type filter, which Name is anything you want and the type is defined in https://developer.apple.com/library/ios/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html#//apple_ref/doc/uid/TP40009259-SW1
Hope you can be success too!!
However, the feature I want to implement is "Share" like Facebook or Slack do, I can not make it still...anyone can give me a big hand :(