从我的应用程序中打开另一个应用程序?

3

我有两个应用程序。 我想要在我的第一个应用程序按钮点击时打开第二个应用程序。 第二个应用程序具有所需的自定义模式,用于深度链接。 现在我想知道在我的第一个应用程序按钮点击时需要执行什么代码才能打开第二个应用程序?


请查看此教程:http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html - Imad Ali
先阅读深度链接。 - Matloob Hasnain
@matloobHasnain 如果应用程序没有提供深度链接呢? - Sagar
@Sagar 如果没有深度链接,就没有打开的方式。 - Matloob Hasnain
3个回答

9
我可以为您提供以下简要信息:您需要为应用程序添加自定义URL模式。
例如,您需要从App1启动App2。这是您需要在App2的Info.plist中添加的代码,或者您可以在目标信息部分中添加“URL Types”。
<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>

这是您需要在App1的info.plist文件中添加的代码。

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

然后您将像这样从App1启动App2:

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

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

希望这能帮到您。

完美运作。你知道如何通过用户名/ID直接导航到应用程序中的特定视图控制器吗?例如,“instagram://user?username=johndoe”会打开Instagram,跳转到用户名为johndoe的个人资料页面。 - luke

0

尝试下面的代码

   let appURL: URL = URL(string: "CustomUrlScheme://")!
    if UIApplication.shared.canOpenURL(appURL) {
        UIApplication.shared.openURL(appURL)
    }

-6
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);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接