Я создаю файл PDF и с помощью UIViewcontroller вызываю файл PDF для просмотра, но по какой-то неизвестной причине мой UIViewcontroller становится нулевым.
string path =
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string filePath = Path.Combine(path,filename);
//Create a file and write the stream into it.
FileStream fileStream = File.Open(filePath, FileMode.Create);
stream.Position = 0;
stream.CopyTo(fileStream);
fileStream.Flush();
fileStream.Close();
//Invoke the saved document for viewing
UIViewController currentController =
UIApplication.SharedApplication.KeyWindow.RootViewController;
while (currentController.PresentedViewController != null)
currentController = currentController.PresentedViewController;
UIView currentView = currentController.View;
QLPreviewController qlPreview = new QLPreviewController();
QLPreviewItem item = new QLPreviewItemBundle(filename, filePath);
qlPreview.DataSource = new PreviewControllerDS(item);
currentController.PresentViewController(qlPreview, true, null);
Это мой файл AppDelegate.cs, пожалуйста, отметьте это
[Register("AppDelegate")]
public partial class AppDelegate :
global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
//CarouselViewRenderer.Init();
FFImageLoading.Forms.Platform.CachedImageRenderer.Init();
LoadApplication(new App());
UIApplication.SharedApplication.StatusBarHidden = true;
return base.FinishedLaunching(app, options);
}
}