iPhone/iPad URL Custom Scheme to open a file

2019-05-31 01:28发布

问题:

I'm trying to intercept some kind of files while using iPad's Safari browser. As you probably know, Safari can't download files, so it would be useful Safari to send my app those files links.

As I've read in the iPhone/iPad developer documentation, you can add an URL Custom Scheme to handle some special protocols (like youtube: or tel: to open either youtube or dial a number), but I don't want to handle a special protocol but a special kind of file using regular http/https protocol.

It would be nice if the URL scheme could be something like:

http://*.zip

I have tried to search some docs, and I've tried even in the simulator, but I cannot be able to design a proper URL Scheme to catch a zip file.

Can I handle this situation using the CFBundleURLTypes and the CFBundleURLSchemes parameters into my application .plist ?

If you cannot do that using this method, is there another way to achieve this?

Thanks ;)

回答1:

Can't do that. Try a custom url scheme like zip://[path to zip file] that opens the zip file with your app. When a user wants to open a zip file, they just change the http(s) to zip. Registering your file type in CFBundleDocumentTypes will only affect the Open With... action sheets in Mail and apps like GoodReader.



回答2:

You should specify the file types your app supports in your Info.plist under the CFBundleDocumentTypes key. Applications who support launching files in other apps (incl. Mail and Safari) can then launch your app and pass the file.

For more info, search the documentation for CFBundleDocumentTypes.