Best Practice for File Locations

TonyValentiTonyValenti USMember ✭✭
edited March 2017 in Xamarin.iOS

Hi All,
I'm working on an app that mounts a network webdav location as a folder that users can access. The app is done and now I'm just working through my one Mac App Store hurdle. I got a rejection notice from the Mac App Store because I was mounting this location into the app's container folder.

What is the right location that I should mount this that would also abide by the sandboxing rules? I was thinking about maybe the downloads folder, but I am worried that people might accidentally delete it if it is inside that folder. If the downloads folder is the right answer, how do I retrieve it?

Any thoughts?

Thanks for your help!

Best Answers

  • TonyValentiTonyValenti US ✭✭
    Accepted Answer

    Hi Chris,
    Thanks for the example. After setting up a sample project I found my issue - App Sandboxing was killing the dialog. I needed an additional entitlement.

    I have two feature requests if you can pass them along:

    1. It would be really nice if Visual Studio for Mac would detect sandboxing violations when they occur and alert them to you. Perhaps even offering a fix. For example, when running my app, it would have been nice if the "Errors" pad said something like "Warning: Sandboxing violation at [....]. Are you missing the .... entitlement?"

    2. It doesn't appear as though the NSOpenPanel maps the "isAccessoryViewDisclosed" property. This prevents me from showing the accessory view by default.

  • ChrisHamonsChrisHamons US Xamurai
    Accepted Answer

    I agree that if we can (I'm not sure what we get back from the debugging side of the hose) we really should do better on sandbox/code signing crashes - https://bugzilla.xamarin.com/show_bug.cgi?id=54344

    And you are correct on that NSOpenPanel selector. Unlike Xamarin.iOS, Xamarin.Mac doesn't have 100% API coverage yet. It's a goal we're working towards, and making steps every release though.

    Until then, since the API was trivial, here's a monkey patch to add it that seems to work:

    https://gist.github.com/chamons/0c3eca631f9cae8ec215240219177e41

Answers

  • TonyValentiTonyValenti USMember ✭✭

    Also, I've been doing some research and I've found that I might need to use app scoped security bookmarks. That's not my preference, but it may be necessary.

    In my app, I have no main window (the app basically runs everything in the background), but I think I need to show an NSOpenPanel in order to allow users to select where they want the files stored.

    I keep getting this error:
    modal session requires modal window

    when I run this code:

    private void DoTest() {
    
                NSApplication.SharedApplication.InvokeOnMainThread(() => {
                    PromptForAccess();
    
                });
    
            }
    
            private void PromptForAccess() {
                var Dialog = NSOpenPanel.OpenPanel;
                Dialog.CanChooseFiles = false;
                Dialog.CanChooseDirectories = true;
                Dialog.CanCreateDirectories = true;
                Dialog.AllowsMultipleSelection = false;
                Dialog.Title = "Choose where you want files stored";
                Dialog.Prompt = "Choose Where you want files stored (prompt)";
                Dialog.WorksWhenModal = true;
                Dialog.BecomesKeyOnlyIfNeeded = true;
    
    
    
                /*
                Dialog.AccessoryView = new NSView();
                Dialog.AccessoryView.AddSubview(new NSTextField() {
                    StringValue = "Please select the folder where you want your Clio files stored.\nThis is usually your 'Home' folder."
                });
    */
    
    
    //I'm trying different options here.  RunModal seems to return immediately.
    //When I do this, I get an error:
    //var App = NSApplication.SharedApplication;            
    //Dialog.MakeKeyAndOrderFront(App);
    //App.RunModalForWindow(Dialog);
    
    
    //And when I do this, RunModal returns immediately.  No modal is ever shown.
    //var Prompt = Dialog.RunModal();
    
    }
    
    
  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    Ok, I think I understand the problem. The Modal Dialog APIs might strongly assume there is a window in view, and a message pump.

    Here's a use from our samples: https://github.com/xamarin/mac-samples/blob/master/MacWindows/MacWindows/AppDelegate.cs#L51

    When you say everything runs in the background, are you still running NSApplication.Main? Do you have a UI thread at all?

  • TonyValentiTonyValenti USMember ✭✭
    Accepted Answer

    Hi Chris,
    Thanks for the example. After setting up a sample project I found my issue - App Sandboxing was killing the dialog. I needed an additional entitlement.

    I have two feature requests if you can pass them along:

    1. It would be really nice if Visual Studio for Mac would detect sandboxing violations when they occur and alert them to you. Perhaps even offering a fix. For example, when running my app, it would have been nice if the "Errors" pad said something like "Warning: Sandboxing violation at [....]. Are you missing the .... entitlement?"

    2. It doesn't appear as though the NSOpenPanel maps the "isAccessoryViewDisclosed" property. This prevents me from showing the accessory view by default.

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai
    Accepted Answer

    I agree that if we can (I'm not sure what we get back from the debugging side of the hose) we really should do better on sandbox/code signing crashes - https://bugzilla.xamarin.com/show_bug.cgi?id=54344

    And you are correct on that NSOpenPanel selector. Unlike Xamarin.iOS, Xamarin.Mac doesn't have 100% API coverage yet. It's a goal we're working towards, and making steps every release though.

    Until then, since the API was trivial, here's a monkey patch to add it that seems to work:

    https://gist.github.com/chamons/0c3eca631f9cae8ec215240219177e41

Sign In or Register to comment.