2017-06-21 178 views
1

我有兩個應用程序。 我想從我的FirstApp按鈕單擊打開一個SecondApp。 第二應用是具有所需的深層鏈接的自定義模式。 現在我想知道我需要什麼代碼,我FirstApp按鈕做點擊打開SecondApp?從我的應用程序打開另一個應用程序?

+0

檢查本教程:http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html –

+0

先閱讀深層鏈接 –

回答

4

多達我可以告訴你在簡短。 您需要爲您的應用程序添加自定義的Url架構。

例如,你需要從應用1推出應用2。

這是你需要的應用2 info.plist中添加代碼,也可以在目標的你的信息部分添加「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> 

這就是你需要在你添加應用1 Info.plist文件中的代碼。

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

然後你將推出應用2從應用1一樣爲:

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

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

希望這會有所幫助。

+0

@Niharika。如果你覺得它可以幫助你。然後將其標記爲可接受的答案。 –

+0

完美地工作。你知道如何直接在應用程序中的某個視圖控制器與用戶名/ ID?例如「instagram://用戶?用戶名= johndoe」用戶名johndoe將簡介頁面打開到配置文件頁面 – luke

0

試試下面的代碼

let appURL: URL = URL(string: "CustomUrlScheme://")! 
    if UIApplication.shared.canOpenURL(appURL) { 
     UIApplication.shared.openURL(appURL) 
    } 
-2
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); 
相關問題