简体   繁体   English

URL Scheme iOS | 以编程方式开源应用程序

[英]URL Scheme iOS | Open Source Application Programmtically

I have 2 iOS applications, using URL Scheme I am able to open app B through A like I have created URL Scheme in B and using OpenURL calling it from application B .我有 2 个iOS应用程序,使用URL Scheme我可以通过A打开应用程序B就像我在B创建了URL Scheme并使用OpenURL从应用程序B调用它一样。 Also, I am able to pass the data.另外,我能够传递数据。

But what I am looking for, is there a way to move back to application A on some specific event.但我正在寻找的是,有没有办法在某些特定事件上移回应用程序A

In B I am getting all details about A in sourceApplication but how to move back?B我在sourceApplication获取有关A所有详细信息,但如何返回?

Do we need to create URL Scheme for both of the apps for communicating with each other?我们是否需要为两个应用程序创建URL Scheme以便相互通信? or is there any way to invoke sourceApplication and move back?或者有什么方法可以调用sourceApplication并返回?

Issue 1第 1 期

in case of Facebook SDK, I create URL Scheme for my app because once authentication is done I want Facebook SDK to call my app that right but I didn't register my app scheme in Facebook SDK info.plist.Facebook SDK,情况下Facebook SDK,我为我的应用程序创建URL Scheme ,因为一旦身份验证完成,我希望Facebook SDK正确调用我的应用程序,但我没有在Facebook SDK info.plist 中注册我的应用程序scheme how does it work?它是如何工作的?

Issue 2 I have tried on Simulator and device both.问题 2我在模拟器和设备上都试过。 if I call canOpenURL it gives me an error如果我调用canOpenURL它会给我一个错误

-canOpenURL: failed for URL: "openb://" - error: "This app is not allowed to query for scheme openb" -canOpenURL:URL 失败:“openb://” - 错误:“此应用程序不允许查询方案 openb”

But If I directly call UIApplication.shared.open it launches the application successfully.但是如果我直接调用UIApplication.shared.open它会成功启动应用程序。

Any leads here?这里有任何线索吗?

If you want to invoke iOS application from another iOS app URL Scheme is the way.如果你想从另一个iOS应用程序调用iOS应用程序URL Scheme是方法。 A URL scheme lets you communicate with other apps through a protocol that you define. URL 方案允许您通过您定义的协议与其他应用程序通信。 To communicate with an app that implements such a scheme, you must create an appropriately formatted URL and ask the system to open it.要与实现此类方案的应用程序进行通信,您必须创建一个格式适当的 URL 并要求系统打开它。 To implement support for a custom scheme, you must declare support for the scheme and handle incoming URLs that use the scheme.要实现对自定义方案的支持,您必须声明对方案的支持并处理使用该方案的传入 URL。

How to move back or open sourceApplication?如何搬回或开源应用?

To achieve this you have to create URL Scheme for both of the application.为此,您必须为两个应用程序创建URL Scheme

Issue 1 and 2问题 1 和 2

Before iOS 8, everyone was using canOpenURL for checking whether this URL is exist for not and if yes openURL for invoking the application.在 iOS 8 之前,每个人都使用canOpenURL来检查此URL是否存在,如果存在则使用openURL来调用应用程序。 But concern came when few developers/apps started using it to track the user iPhone (what all application is installed) for advertising purposes etc. That's why Apple came up with the solution called URL Scheme Whitelist .但是当很少有开发人员/应用程序开始使用它来跟踪用户 iPhone(安装了所有应用程序的内容)用于广告目的等时,担忧就来了。这就是为什么Apple提出了名为URL Scheme Whitelist的解决URL Scheme Whitelist

So according to that, if you want to use canOpenURL you have to whitelist the URL Scheme otherwise it will through an error like error: This app is not allowed to query for scheme and if you want to open the application use openURL directly.因此,如果您想使用canOpenURL您必须将URL Scheme列入白名单,否则它会通过类似error: This app is not allowed to query for scheme ,如果您想直接打开应用程序,请使用openURL

Yes it broke lots of SDKs login flow but it makes sense.是的,它破坏了许多 SDK 登录流程,但它是有道理的。

For more information, canOpenURL(_:)有关更多信息,请参阅 canOpenURL(_:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM