2016-09-19 111 views
2

我以前用過this way打開默認的應用程序文件,但iOS的10起它不會在iPhone(應用程序崩潰)的工作,但它工作正常在iPad上。打開文件

什麼是從DependencyService打開文件的正確方法?

因爲我目前還沒有的iOS設備10上測試,我不能得到的錯誤。

+1

這最終可能會幫助您:https://riccardo-moschetti.org/2014/10/03/opening-a-mobile-app-from-a-link-the -xamarin-way-url-schemas/ –

+0

然後你必須知道URL模式 –

+2

你可以在模擬器上試試它,並找到錯誤發生的地方? 「不起作用」是什麼意思? (應用程序崩潰,沒有任何反應,快速查看出現空白屏幕,別的?)。我沒有看到Quick Look框架行爲的任何記錄更改。 – dylansturg

回答

0

你需要知道你正在試圖打開該應用程序的URL計劃; URL Schemes是在應用程序之間進行通信的唯一方式。

你沒有指定哪些應用程式你試圖打開,所以我已經包括下面展示瞭如何使用URL方案打開設置應用,郵件應用程序和App Store應用程序的示例代碼(到特定應用程序)。

蘋果additional documentation on URL Schemes here

using UIKit; 
using MessageUI; 
using Foundation; 

using Xamarin.Forms; 

using SampleApp.iOS; 

[assembly: Dependency(typeof(DeepLinks_iOS))] 
namespace SampleApp.iOS 
{ 
    public class DeepLinks_iOS : IDeepLinks 
    { 
     public void OpenStoreLink() 
     { 
      Device.BeginInvokeOnMainThread(() => UIApplication.SharedApplication.OpenUrl(new NSUrl("https://appsto.re/us/uYHSab.i"))); 
     } 

     public void OpenFeedbackEmail() 
     { 
      MFMailComposeViewController mailController; 

      if (MFMailComposeViewController.CanSendMail) 
      { 
       mailController = new MFMailComposeViewController(); 

       mailController.SetToRecipients(new string[] { "[email protected]" }); 
       mailController.SetSubject("Email Subject String"); 
       mailController.SetMessageBody("This text goes in the email body", false); 

       mailController.Finished += (object s, MFComposeResultEventArgs args) => 
       { 
        args.Controller.DismissViewController(true, null); 
       }; 

       var currentViewController = GetVisibleViewController(); 
       currentViewController.PresentViewController(mailController, true, null); 
      } 
     } 

     public void OpenSettings() 
     { 
      Device.BeginInvokeOnMainThread(() => UIApplication.SharedApplication.OpenUrl(new NSUrl(UIApplication.OpenSettingsUrlString))); 
     } 


     static UIViewController GetVisibleViewController() 
     { 
      var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController; 

      if (rootController.PresentedViewController == null) 
       return rootController; 

      if (rootController.PresentedViewController is UINavigationController) 
      { 
       return ((UINavigationController)rootController.PresentedViewController).TopViewController; 
      } 

      if (rootController.PresentedViewController is UITabBarController) 
      { 
       return ((UITabBarController)rootController.PresentedViewController).SelectedViewController; 
      } 

      return rootController.PresentedViewController; 
     } 
    } 
}