2016-04-22 97 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可以將照片保存到相機膠捲中,您可以根據它進行自己的解決方案。

希望這會有所幫助!

相關問題