简体   繁体   English

AccessDenied 在 Xamarin.Forms.Platform.iOS.FormsApplicationDelegate OpenUrl

[英]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.

相关问题 Xamarin Forms Webview 在 IOS 平台上禁用缩放 - Xamarin Forms Webview Disable zoom on IOS platform 更改每个平台的Xamarin Forms版本-iOS,Android和共享 - Change Xamarin Forms version for each platform - iOS, Android & Shared Xamarin Forms在iOS平台上未收到Appcenter推送通知 - Appcenter push notifications not received by Xamarin Forms on iOS platform iOS 15 更新后,iOS 平台中 Xamarin.forms 中的导航栏颜色变化问题 - Navigation bar colour change issue in Xamarin.forms in iOS platform after iOS 15 update iOS App(Xamarin)与iOS XAML App(Xamarin.Forms)与跨平台之间的区别是什么 - What are diffs between iOS App (Xamarin) vs. iOS XAML App (Xamarin.Forms) vs. Cross-Platform Xamarin表格清除会话iOS Xamarin表格 - xamarin forms clear session ios xamarin forms Xamarin Forms Geolocator IOS - Xamarin Forms Geolocator IOS “尝试使用UIImagePickerController呈现其视图不在窗口层次结构中的Xamarin_Forms_Platform_iOS_ModalWrapper”错误 - “Attempt to present Xamarin_Forms_Platform_iOS_ModalWrapper whose view is not in the window hierarchy” error with UIImagePickerController Xamarin跨平台iOS应用 - Xamarin cross platform iOS app 找不到Xamarin.Forms.Platform.Android.LabelRenderer(xamarin表单)的构造函数 - No constructor found for Xamarin.Forms.Platform.Android.LabelRenderer (xamarin forms)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM