2016-09-19 109 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; 
     } 
    } 
}