2017-05-12 154 views
1

我試圖測試一個應用程序是否存在從MyApp(CanOpen)。如果是這樣,我希望打開該應用程序,否則我有一個https地址來打開webview。我在開放測試中獲得虛假回報。我相信我的代碼是正確的,但我不確定在info.plist上。我有一個url類型(在info.plist中)MyApp。我對其他應用程序(健康)的LSApplicationQueriesSchemes項,但不能確定那參考如何回接到實際應用....任何幫助是極大的讚賞:從Xamarin Forms應用程序啓動另一個IOS應用程序

在MyApp的PCL是以下接口:

public interface IAppHandler 
    { 
     Task<bool> LaunchApp(string uri); 
    } 

在模型視圖,我作出deoendency調用實際的處理程序:

string appid = @"health://"; 
    var result = await DependencyService.Get<IAppHandler>().LaunchApp(appid); 

    if (!result) 
    { 
     Show_WebView(url); 
    } 

在T他特定於平臺的AppHandler:

public Task<bool> LaunchApp(string uri) 
{ 
    try 
    { 
     var canOpen = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(uri)); 
     if (!canOpen) 
      return Task.FromResult(false); 
     return Task.FromResult(UIApplication.SharedApplication.OpenUrl(new NSUrl(uri))); 
    } 
    catch (Exception ex) 
    { 
     return Task.FromResult(false); 
    } 
} 

在info.plist中:

<key>CFBundleURLSchemes</key> 
<array> 
    <string>MyApp</string> 
    <string>com.apple.Health</string> 
</array> 
<key>LSApplicationQueriesSchemes</key> 
<array> 
    <string>health</string> 
</array> 
+0

您需要註冊您想要打開的應用程序的URLScheme。 –

+0

Shabir,使用捆綁ID?謝謝 – Nick

+0

我錯過了如何將LSApplicationQueriesSchemes綁定到URL類型。 – Nick

回答

1

您需要添加目標應用程序的URL計劃到Info.plist文件,以便使用canOpen功能。即 enter image description here

+0

是否保留您在OpenApp聲明中使用的名稱?什麼是accom.ibm-cognos-mobile? – Nick

+0

你可以用XML來展示它嗎? – Nick

+0

兩者都是2種不同應用程序的URL方案 –

相關問題