C# 如何在ios 11中保存Tophotosalbum崩溃?
当我们运行下面提到的代码在照片库中下载并保存图像时,它会在ios 11中自动崩溃。请指导解决这个问题C# 如何在ios 11中保存Tophotosalbum崩溃?,c#,ios,xamarin,xamarin.ios,C#,Ios,Xamarin,Xamarin.ios,当我们运行下面提到的代码在照片库中下载并保存图像时,它会在ios 11中自动崩溃。请指导解决这个问题 try { string uri = "https://www.xamarin.com/content/images/pages/branding/assets/xamagon.png"; using (var url = new NSUrl(uri)) using (var data = NSData.FromUrl(url)) UIImage.LoadFro
try
{
string uri = "https://www.xamarin.com/content/images/pages/branding/assets/xamagon.png";
using (var url = new NSUrl(uri))
using (var data = NSData.FromUrl(url))
UIImage.LoadFromData(data).SaveToPhotosAlbum((image, error) =>
{
var o = image as UIImage;
Console.WriteLine("error:" + error);
});
}
catch(Exception exx)
{
throw exx;
}
您应该添加这个,iOS 11更新
<key>NSPhotoLibraryAddUsageDescription</key>
<string>$(PRODUCT_NAME) would like to use Photo Library</string>
NSPhotoLibraryAddUsageDescription
$(产品名称)要使用照片库
Swift-4、Xcode 9、IOS 11
Info.plist
<key>NSPhotoLibraryUsageDescription</key>
<string> photos description.</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string> photos add description.</string>
请仔细阅读问题,这是针对xamarin而非iOS Swiftsee的:
let url = "https://www.xamarin.com/content/images/pages/branding/assets/xamagon.png"
let data = try! Data(contentsOf: URL(string: url)!)
let image:UIImage = UIImage(data: data)!
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
@objc func image(_ image: UIImage, didFinishSavingWithError error: NSError?, contextInfo: UnsafeRawPointer) {
if let error = error {
// we got back an error!
let ac = UIAlertController(title: "Save error", message: error.localizedDescription, preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default))
present(ac, animated: true)
} else {
let ac = UIAlertController(title: "Saved!", message: "The image has been saved to your photos.", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default))
present(ac, animated: true)
}
}