本机iOS应用程序是否可以与Safari浏览器进行交互?

时间:2022-09-15 10:48:48

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 context menu to send the image to another custom written native iOS application for further processing and/or storage.

我希望启用本机iOS应用程序和Safari浏览器之间的交互,以便点击网页上的图像右键单击可在上下文菜单中提供一个选项,将图像发送到另一个自定义编写的本机iOS应用程序以进行进一步处理和/或存储。

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

但是,根据Safari Developer Library的这篇文章,“iOS目前不支持Safari扩展”。

Is there any other alternative to achieve the above functionality?

有没有其他替代方案来实现上述功能?

2 个解决方案

#1


6  

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.
  • 您可以在应用程序的Info.plist文件中注册您的应用程序知道如何处理某些类型的文档(请参阅Apple的文档)。这样,当您的iPhone遇到此文档类型时,iOS会建议用户在您的应用中打开此文档;例如,如果您注册了PDF类型,然后点击PDF文档作为邮件中的附件,您的应用程序将列在建议的菜单中,然后将该文档作为参数打开。

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 :(

但似乎即使这适用于任何类型,如DOC,PDF,甚至自定义类型,它也不适用于图像,这似乎是由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.
  • 一种更简单的方法是在应用程序的Info.plist中注册任何自定义URL方案。请参阅Apple的文档中的此处和下方。例如,当你在iPhone的任何地方(无论是在你自己的应用程序中,还是在其他第三方应用程序中,包括Safari),它会遇到像“myapp:// xxx / yyy / zzz”这样的网址,它会打开你的应用程序,通过这个URL作为参数。然后,您可以使用此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.

然后解决方案是在您的网页中添加一些代码,以便在点击图像时,您要求Safari打开URL“myimageditor:// edit?url = http://www.url.of/your/image。 JPG”。如果您注册了“myimageeditor://”URL方案,那么您将使用参数中的URL打开应用程序,然后您就可以使用嵌入URL检索图像。

#2


0  

I think it is possible only for jailbroken devices.

我认为只有越狱设备才有可能。

#1


6  

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.
  • 您可以在应用程序的Info.plist文件中注册您的应用程序知道如何处理某些类型的文档(请参阅Apple的文档)。这样,当您的iPhone遇到此文档类型时,iOS会建议用户在您的应用中打开此文档;例如,如果您注册了PDF类型,然后点击PDF文档作为邮件中的附件,您的应用程序将列在建议的菜单中,然后将该文档作为参数打开。

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 :(

但似乎即使这适用于任何类型,如DOC,PDF,甚至自定义类型,它也不适用于图像,这似乎是由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.
  • 一种更简单的方法是在应用程序的Info.plist中注册任何自定义URL方案。请参阅Apple的文档中的此处和下方。例如,当你在iPhone的任何地方(无论是在你自己的应用程序中,还是在其他第三方应用程序中,包括Safari),它会遇到像“myapp:// xxx / yyy / zzz”这样的网址,它会打开你的应用程序,通过这个URL作为参数。然后,您可以使用此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.

然后解决方案是在您的网页中添加一些代码,以便在点击图像时,您要求Safari打开URL“myimageditor:// edit?url = http://www.url.of/your/image。 JPG”。如果您注册了“myimageeditor://”URL方案,那么您将使用参数中的URL打开应用程序,然后您就可以使用嵌入URL检索图像。

#2


0  

I think it is possible only for jailbroken devices.

我认为只有越狱设备才有可能。