0

In iOS, you can modify your plist to associate a filetype with your app, so if the user selects that file, an 'Open with...' menu pops up. How can I get my app in "Open with" (by using CFBundleDocumentTypes)

But, how can I do this for a deep link that doesn't represent any file? In other words, I just want to send a deep link out through email that resolves in an App Switcher, to let the user select between 3 different apps.

I am not hosting or sending any file. I just need to pass data parameters, the same way a regular deep-link does, but it can be opened in 3 different apps, not just 1.

FranticRock
  • 3,233
  • 1
  • 31
  • 56

1 Answers1

1

If it's a known file type (i.e. not a file type/extension that you've made up), then you can add the into to the Info.plist. Here are the steps:

1) Click on your project in XCode and select the "Info" tab

2) Towards the bottom, you should see the "Document Types"; you'll need to add your document type. For the name, you can write anything. For the types, you should go refer to: https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html#//apple_ref/doc/uid/TP40009259-SW1

3) Last step is to expand the "Additional document type properties" and add a key value pair. The key should be "LSHandlerRank" of type string. The value should be "Alternate."

If you have a custom type, you'll go through the same steps with some exception:

1) Add a document type with whatever name you want.

2) Add a type that conforms to your project; for example, if you worked for the Example Company with a file type of abc, I would add "com.example.abc" to the Types.

3) Next, you'll need to add a value to the "Imported UTIs" area. For the description, use whatever you want.

4) For the identifier, use the same value that you entered in step 2 (i.e. "com.example.abc")

5) For the "Conforms To", reference Apple's Documentation here: https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/understanding_utis/understand_utis_conc/understand_utis_conc.html#//apple_ref/doc/uid/TP40001319-CH202-BCGJGJGA

6) Under "Additional UTI Properties" you'll add a Dictionary labeled "UTTypeTagSpecification"

7) Under the dictionary, add an Array labeled "public.filename-extension"

8) Under the array, add two items. The first should be the uppercase version of your extension ("ABC") and the second should be the lowercase version of your extension ("abc").

That should allow the app to pop up in the "Open With" menu that iOS displays. In order to handle the fill though, you'll need to add the following function to your AppDelegate:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool

That should do it!

binaryPilot84
  • 994
  • 6
  • 20
  • I will try the steps shortly. Do you think the following URL format would work: http://localhost/appHook.myCustomExtension?myParamId=paramValues ? So as long as I register .myCustomExtension . or (.mce, etc), as per above, then the HTTP URL would resolve in my app? I wonder if Safari would prioritize the HTTP scheme, or my custom file extension would take priority? It's basically not a deep link, because the scheme can be one of a few apps, so i was thinking to use HTTP as a scheme (since I don't know ahead of time which of the apps would be installed). – FranticRock Aug 28 '18 at 18:46
  • And I also presume that appHook.myCustomExtension (the file) doesn't have to actually exist. It's just a trick to present the app switcher, and pass params to one of many apps. (Mimicking a "one-to-many" deep-link). – FranticRock Aug 28 '18 at 18:50
  • What I described above will allow you to open the file with the .myCustomExtension. What you have described in the comment looks like a web address. What will that web address produce? If it's another webpage, then it won't open using the steps above. If it produces a file of the type .myCustomExtension, then it should work. Regarding Safari, if it can handle the extension, then I think it will display it natively. That being said, there should be an "Open With" option displayed that still allows you to do what you want. – binaryPilot84 Aug 28 '18 at 18:54
  • My main challenge is I don't know what the URL SCHEME will be ahead of time. So I can't go: MyApp://Route. Because I don't know what "MyApp" will be ahead of time. (Our platform has to work for any app that handles it's Deep Links) . So it's a dynamic deeplink basically. And I'm hoping to use the file extension as a way to invoke the "open with" sheet, but without having any actual file, and still allow passing parameters as needed, the way a deep link does. – FranticRock Aug 28 '18 at 19:15
  • @FranticRock, the URL itself should not matter. When you navigate to the URL in question (or any of the possible URLs), what is displayed in the browser? If it's the option to download a file with your associated file extensions, this should work regardless of the URL scheme. – binaryPilot84 Aug 28 '18 at 19:24
  • John, sorry for the delay. I will put together 2 sample projects to test this out with tomorrow and I will post my findings. Thanks. – FranticRock Sep 04 '18 at 04:07
  • How did your test go? – binaryPilot84 Sep 09 '18 at 16:00