[英]AccessDenied in Xamarin.Forms.Platform.iOS.FormsApplicationDelegate OpenUrl
I have registered my file type and when I am trying to read the passed file, I always get an access denied exception.我已经注册了我的文件类型,当我尝试读取传递的文件时,我总是收到拒绝访问异常。 This is my current code:
这是我当前的代码:
public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
{
var text = File.ReadAllText(url.Path); <- Exception here
// todo: handle text
return true;
}
On android I got it working with the ContentResolver:在 android 上,我让它与 ContentResolver 一起工作:
using (var inputStream = ContentResolver.OpenInputStream(Intent.Data))
{
using (StreamReader reader = new StreamReader(inputStream))
{
string text = reader.ReadToEnd();
Clipboard.SetTextAsync(text);
}
}
but I did not find an equivalent to read the passed file on iOS.但我没有找到等效的读取 iOS 上传递的文件。
Take a look at this thread: Handling application: openURL: sourceApplication: to open files in iOS app .看看这个线程: Handling application: openURL: sourceApplication: to open files in iOS app 。
I convert objective-C to c#, you could try it in your project.我将 objective-C 转换为 c#,您可以在您的项目中尝试。
public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
{
string urlPath = url.Path;
NSData data = null;
if (!NSFileManager.DefaultManager.IsReadableFile(urlPath)) {
if (url.StartAccessingSecurityScopedResource())
{
data = NSData.FromFile(urlPath);
url.StopAccessingSecurityScopedResource();
}
}
else
{
data = NSData.FromFile(urlPath);
}
NSString str = NSString.FromData(data, NSStringEncoding.UTF8);
return true;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.