简体   繁体   English

从“我的应用”中打开另一个应用?

[英]Open another app from My app?

I am having two apps. 我有两个应用程序。 I want to open a SecondApp from my FirstApp Button Click. 我想通过FirstApp按钮单击打开SecondApp。 Second App is having that custom Schema which is required for deep linking. Second App具有深链接所需的自定义架构。 Now I want to know what code I need to do on my FirstApp button click to open SecondApp? 现在,我想知道在FirstApp按钮单击以打开SecondApp时需要做什么代码?

As much I can tell you in brief. 我可以简要地告诉你。 You need to add custom Url schema for in your application. 您需要在应用程序中添加自定义的Url模式。

For example you need to launch App2 from App1. 例如,您需要从App1启动App2。

This is the code that you need to add in App2 info.plist or you can add "URL Types" in your info section of target. 这是您需要在App2 info.plist中添加的代码,也可以在目标的info部分中添加“ URL类型”。

<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>com.company.App1</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>CompanyApp2</string>
        </array>
    </dict>
</array>

And this is the code that you need to add in you App1 info.plist file. 这是您需要在App1 info.plist文件中添加的代码。

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>CompanyApp2</string>
</array>

Then you will launch App2 from App1 like as: 然后,您将从App1启动App2,如下所示:

        let app2Url: URL = URL(string: "CompanyApp2://")!

        if UIApplication.shared.canOpenURL(app2Url) {
            UIApplication.shared.openURL(app2Url)
        }

Hope this will help. 希望这会有所帮助。

Try below code 试试下面的代码

   let appURL: URL = URL(string: "CustomUrlScheme://")!
    if UIApplication.shared.canOpenURL(appURL) {
        UIApplication.shared.openURL(appURL)
    }
In android, we can perform in the below ways
//Dial a phone
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:0377778888"));
startActivity(callIntent);

//View a map
// Map point based on address
Uri location = Uri.parse("geo:0,0?q=1600+Amphitheatre+Parkway,+Mountain+View,+California");
// Or map point based on latitude/longitude
// Uri location = Uri.parse("geo:37.422219,-122.08364?z=14"); // z param is zoom level
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);
startActivity(mapIntent);
//View a webpage
Uri webpage = Uri.parse("http://www.android.com");
Intent webIntent = new Intent(Intent.ACTION_VIEW, webpage);
startActivity(webIntent);

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

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