开发者

Is it possible for native iOS application to interact with Safari browser?

开发者 https://www.devze.com 2023-04-03 14:14 出处:网络
I would like to enable interaction between a native iOS application and the Safari browser such that tapping a right click on an image on a webpage provides an option in the con开发者_开发技巧text men

I would like to enable interaction between a native iOS application and the Safari browser such that tapping a right click on an image on a webpage provides an option in the con开发者_开发技巧text menu to send the image to another custom written native iOS application for further processing and/or storage.

However, according to this article from Safari Developer Library, “Safari extensions are not currently supported on iOS”.

Is there any other alternative to achieve the above functionality?


You have multiple choices here:

  • You could register in your application's Info.plist file that your app known how to handle certain type of documents (see here in Apple's doc). This way when your iPhone encounters this document type, iOS will propose the user to open this document in your app; for example if you register for the PDF type and you then tap on a PDF document as an attachment in a mail, you app will be listed in the proposed menu and will then be opened with the document as a parameter.

But it seems that even if this works perfectly for any type like DOC, PDF, or even custom types, it does not work for images, which seems to be handled in a separate way by iOS :(

  • A simpler way would be to register, still in your application's Info.plist, any custom URL schemes. See here and below in the Apple's doc. For example when, anywhere in your iPhone (either in your own app, or in another third-party app, including Safari), it encounters URLs like "myapp://xxx/yyy/zzz", it opens your app, passing this URL as an argument. You can then do whatever you want with this URL.

The solution then is to add some code in your web page so that when the image is tapped, you ask Safari to open the URL "myimageditor://edit?url=http://www.url.of/your/image.jpg". If you registered for the "myimageeditor://" URL scheme, you app will then open with the URL in the parameters, and you then will be able to retrieve the image using the embed URL.


I think it is possible only for jailbroken devices.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号