2016-04-22 99 views
1

我已经从网络服务下载图像,并且需要在Safari内打开图像或将其保存到相机胶卷。我试图在Safari中打开图像,但Safari浏览器无法打开。用图像启动Safari或保存到相机胶卷问题

var safari = UIApplication.SharedApplication; 
var uri = new NSUrl(path); // where the image is saved to 
safari.OpenUrl(uri); 

这编译,但Safari浏览器没有启动

我必须保存至相机胶卷中的代码是这样的

PHPhotoLibrary.SharedPhotoLibrary.PerformChanges(() => 
{ 
     using (var pool3 = new NSAutoreleasePool()) 
     {          pool3.InvokeOnMainThread(delegate() 
      {                PHAssetChangeRequest.FromImage((UIImage)UIImage.FromFile(path)); 
      }); 
     } 
     }, (t, err) => 
     { 
      if (!t) 
      { 
       using (var pool1 = new NSAutoreleasePool()) 
       { 
         pool1.InvokeOnMainThread(delegate() { 
          var alert = new UIAlertView("Error saving file", "An error has occured saving your photo to the camera roll", null, "OK"); 
          alert.Show(); 
          }; 
      } 
      else 
      { 
       using (var pool2 = new NSAutoreleasePool()) 
       { 
         pool2.InvokeOnMainThread(delegate(){ 
          var alert = new UIAlertView("Image saved", "Your image has been saved to the camera roll", null, "OK"); 
          alert.Show(); 
          }); 
         }; 
       } 
     }); 

其崩溃和烧伤(正确的权限已设置)

我不知道为什么这些工作看起来都是正确的。

回答

0

您无法使用Safari浏览器打开本地路径,这是iOS不允许的(应用程序被沙箱化),因此您需要使用远程URL或使用您自己的UIWebViewWKWebViewSFSafariViewController来显示在像经验一样的Safari浏览器中的图像。 Here is a blog post in the Xamarin Site关于这个问题。

此处还有一个不错的recipe in the Xamarin site可以将照片保存到相机胶卷中,您可以根据它进行自己的解决方案。

希望这会有所帮助!

相关问题