如何启动打开我的自定义网址方案的应用程序? [英] How can I launch back the app that opened my custom URL scheme?

查看:157
本文介绍了如何启动打开我的自定义网址方案的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个管理我自己的URL方案的应用程序,因此我实现回调:

   - (BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions(NSDictionary *)launchOptions 
{
//获取我们的启动URL
if(launchOptions!= nil)
{
//启动字典有数据
NSURL * launchURL = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];

//解析URL
NSString * hostString = [launchURL host];

blah blah blah ...

以启动调用者应用程序(即打开URL的应用程序)。



我一直在玩 UIApplicationLaunchOptionsSourceApplicationKey ,但我无法启动通过应用程序捆绑ID退回应用程序。我可以吗?



我也尝试过 launchApplicationWithIdentifier: UIApplication ,但我需要一个真正的解决方案,似乎解决方法只适用于模拟器。



任何想法?谢谢!

解决方案

唯一的方法是让这两个应用程序都支持自定义网址方案。然后将调用者URL嵌入到其他应用程序的URL中。



例如,让App2想调用App1,这样App1就可以回调到App2。它将创建并打开如下所示的URL:

  app1://?caller = app2%3A%2F%2Fblabla 

当您解码调用者字符串 app2:// blabla ,然后您可以再次使用 openURL: p>

I'm working on an app that manages my own URL scheme so I implement the callback:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions (NSDictionary *)launchOptions
{
    // Get our launch URL
    if (launchOptions != nil)
    {
        // Launch dictionary has data
        NSURL* launchURL = [launchOptions objectForKey: UIApplicationLaunchOptionsURLKey];

        // Parse the URL
        NSString* hostString = [launchURL host];

        blah blah blah...

It works very nice but I need to launch the caller application (i.e. the app that opened the URL). So my question here is, is it possible?

I have been playing with UIApplicationLaunchOptionsSourceApplicationKey but I can't launch back the app by its application Bundle ID. Can I?

I have also tried the undocumented launchApplicationWithIdentifier: of UIApplication, but I need a real solution and it seems that workaround only works in the Simulator.

Any ideas? Thank you!

解决方案

The only way would be to have both apps each support a custom URL scheme. Then you embed the caller URL in the URL of the other app.

For example, let's say App2 wants to call App1 in a way so that App1 could then "call back" to App2. It would create and open an URL like this:

app1://?caller=app2%3A%2F%2Fblabla

When you decode the caller part you would get back the string app2://blabla which you could then again open with openURL: to "call back".

这篇关于如何启动打开我的自定义网址方案的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆