question

Te-5304 avatar image
0 Votes"
Te-5304 asked RobCaplan edited

Accessing file stored in "On My iPhone" in iOS Xamarin Application

I need my application to be able to read a file in the "On My iPhone" folder in the files application of an iphone. The file would be downloaded from an email and into that directory. Would it be possible for an iOS application to access the file downloaded from email and into that directory? And if so, I would I go about doing that?

Thank you in advance!

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LeonLu-MSFT avatar image
1 Vote"
LeonLu-MSFT answered LeonLu-MSFT commented

Hello,​

Welcome to our Microsoft Q&A platform!

Yes, you can read it by UIDocumentPickerViewController. Add add following two keys to your Info.plist

<key>UIFileSharingEnabled</key>
    <true/>
    <key>LSSupportsOpeningDocumentsInPlace</key>
    <true/>

Here is demo code. I picker the text file, then return the text file's NSUrl


public partial class ViewController : UIViewController
    {
        public ViewController(IntPtr handle) : base(handle)
        {
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            UIButton button = new UIButton() {

                Frame = new CoreGraphics.CGRect(10, 100, 200, 80),
                BackgroundColor = UIColor.LightGray,

          };
            button.SetTitle("Click", UIControlState.Normal);
            button.TouchUpInside += Button_TouchUpInside;

            View.AddSubview(button);

            // Perform any additional setup after loading the view, typically from a nib.
        }

        private void Button_TouchUpInside(object sender, EventArgs e)
        {
            string[] strs = {"public.image","public.text", };

            //NSArray arr = NSArray.FromStrings(strs);

            UIDocumentPickerViewController controller = new UIDocumentPickerViewController(strs,UIDocumentPickerMode.Open);


            controller.Delegate = new PickerClass();

            UIApplication.SharedApplication.Windows[0].RootViewController.PresentViewController(controller,true,null);

        }

        public override void DidReceiveMemoryWarning()
        {
            base.DidReceiveMemoryWarning();
            // Release any cached data, images, etc that aren't in use.
        }
    }


    public class PickerClass : UIDocumentPickerDelegate, IUIDocumentInteractionControllerDelegate
    {
        public override void DidPickDocument(UIDocumentPickerViewController controller, NSUrl url)
        {

            var path = url.AbsoluteString;

        }
    }



Best Regards,

Leon Lu



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello, thank for you the response!

I'm able to open the files app and see all the files in there from my application but all the files are greyed out and I'm not able to actually select any of them.

0 Votes 0 ·