NSSavePanel runModal isn't working in sandbox?

  • Hi,

    I'm having trouble with NSSavePanel runModal in a sandbox:

    NSSavePanel * savePanel = [NSSavePanel savePanel];
    savePanel.title = @"Document Migration";
    savePanel.directoryURL = url;
    savePanel.nameFieldStringValue = [url lastPathComponent];
    savePanel.allowedFileTypes = [NSArray arrayWithObject:typeName];
    savePanel.message = @"Your document needs to be upgraded.";

    [savePanel setCanSelectHiddenExtension:YES];
    [savePanel setExtensionHidden:YES];

    NSInteger result = [savePanel runModal];

    if (result == NSFileHandlingPanelOKButton) {
    NSAssert(savePanel.URL != nil, @"NSSavePanel returned nil for URL");

    Without the sandbox, it works fine, with the sandbox, the savePanel.URL is
    nil.

    Any ideas what is going on? I looked at the documentation on sandbox and it
    didn't mention anything about runModal. I'm going to try using the
    completion handler method...

    Kind regards,
    Samuel
  • Are you aware that this class is riddled with severe bugs under the current sandbox implementation?

    The dev forums will reveal more details.

    Also, NSSavePanel doesn't inherit from NSPanel under sandboxing, so if you are expecting to use inherited methods, they don't work.

    File bugs - we can't adopt sandboxing until these issues are properly fixed.

    --Graham

    On 06/06/2012, at 1:41 PM, Samuel Williams wrote:

    > Hi,
    >
    > I'm having trouble with NSSavePanel runModal in a sandbox:
    >
    > NSSavePanel * savePanel = [NSSavePanel savePanel];
    > savePanel.title = @"Document Migration";
    > savePanel.directoryURL = url;
    > savePanel.nameFieldStringValue = [url lastPathComponent];
    > savePanel.allowedFileTypes = [NSArray arrayWithObject:typeName];
    > savePanel.message = @"Your document needs to be upgraded.";
    >
    > [savePanel setCanSelectHiddenExtension:YES];
    > [savePanel setExtensionHidden:YES];
    >
    > NSInteger result = [savePanel runModal];
    >
    > if (result == NSFileHandlingPanelOKButton) {
    > NSAssert(savePanel.URL != nil, @"NSSavePanel returned nil for URL");
    >
    >
    > Without the sandbox, it works fine, with the sandbox, the savePanel.URL is
    > nil.
    >
    > Any ideas what is going on? I looked at the documentation on sandbox and it
    > didn't mention anything about runModal. I'm going to try using the
    > completion handler method...
  • Hi Graham,

    What dev forums are you talking about?

    NSSavePanel seems completely unusable.

    Even the simplest example isn't working for me:

    - (void) finishLaunching {
    [super finishLaunching];
    NSSavePanel * savePanel = [NSSavePanel savePanel];
    [savePanel runModal];
    NSLog(@"End model session for savePanel: %@", savePanel.URL);
    }

    That gives nil as a result.

    The fact is that the documentation on Apple's site doesn't mention any
    existing issues so it is very frustrating to have spent several days
    banging my head against these issues wondering if it is something to do
    with my code or not... Thanks for clarifying the situation.

    Kind regards,
    Samuel

    On 6 June 2012 16:50, Graham Cox <graham.cox...> wrote:

    > Are you aware that this class is riddled with severe bugs under the
    > current sandbox implementation?
    >
    > The dev forums will reveal more details.
    >
    > Also, NSSavePanel doesn't inherit from NSPanel under sandboxing, so if you
    > are expecting to use inherited methods, they don't work.
    >
    > File bugs - we can't adopt sandboxing until these issues are properly
    > fixed.
    >
    >
    > --Graham
    >
    >
    >
    >
    >
    > On 06/06/2012, at 1:41 PM, Samuel Williams wrote:
    >
    >> Hi,
    >>
    >> I'm having trouble with NSSavePanel runModal in a sandbox:
    >>
    >> NSSavePanel * savePanel = [NSSavePanel savePanel];
    >> savePanel.title = @"Document Migration";
    >> savePanel.directoryURL = url;
    >> savePanel.nameFieldStringValue = [url lastPathComponent];
    >> savePanel.allowedFileTypes = [NSArray arrayWithObject:typeName];
    >> savePanel.message = @"Your document needs to be upgraded.";
    >>
    >> [savePanel setCanSelectHiddenExtension:YES];
    >> [savePanel setExtensionHidden:YES];
    >>
    >> NSInteger result = [savePanel runModal];
    >>
    >> if (result == NSFileHandlingPanelOKButton) {
    >> NSAssert(savePanel.URL != nil, @"NSSavePanel returned nil for URL");
    >>
    >>
    >> Without the sandbox, it works fine, with the sandbox, the savePanel.URL
    > is
    >> nil.
    >>
    >> Any ideas what is going on? I looked at the documentation on sandbox and
    > it
    >> didn't mention anything about runModal. I'm going to try using the
    >> completion handler method...
    >
    >
  • On 06/06/2012, at 2:55 PM, Samuel Williams wrote:

    > Hi Graham,
    >
    > What dev forums are you talking about?
    >

    If you are a registered apple developer, there are a number of forms at developer.apple.com, including one for sandboxing issues.

    > The fact is that the documentation on Apple's site doesn't mention any existing issues so it is very frustrating to have spent several days banging my head against these issues wondering if it is something to do with my code or not... Thanks for clarifying the situation.

    No, they seem to like to pretend it's all working just fine in the documentation. However, Apple engineers contributing to the forums are more candid.

    The current documentation does talk about the differences with NSSavePanel, or at least how it's supposed to work:

    https://developer.apple.com/library/mac/#documentation/Security/Conceptual/
    AppSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html#//apple_ref/
    doc/uid/TP40011183-CH3-SW4


    --Graham
  • What entitlements do you have?

    On 6 Jun 2012, at 04:41, Samuel Williams wrote:

    > Hi,
    >
    > I'm having trouble with NSSavePanel runModal in a sandbox:
    >
    > NSSavePanel * savePanel = [NSSavePanel savePanel];
    > savePanel.title = @"Document Migration";
    > savePanel.directoryURL = url;
    > savePanel.nameFieldStringValue = [url lastPathComponent];
    > savePanel.allowedFileTypes = [NSArray arrayWithObject:typeName];
    > savePanel.message = @"Your document needs to be upgraded.";
    >
    > [savePanel setCanSelectHiddenExtension:YES];
    > [savePanel setExtensionHidden:YES];
    >
    > NSInteger result = [savePanel runModal];
    >
    > if (result == NSFileHandlingPanelOKButton) {
    > NSAssert(savePanel.URL != nil, @"NSSavePanel returned nil for URL");
    >
    >
    > Without the sandbox, it works fine, with the sandbox, the savePanel.URL is
    > nil.
    >
    > Any ideas what is going on? I looked at the documentation on sandbox and it
    > didn't mention anything about runModal. I'm going to try using the
    > completion handler method...
    >
    > Kind regards,
    > Samuel
  • On Jun 6, 2012, at 13:08 , <cocoa-dev-request...> wrote:
    > Date: Wed, 06 Jun 2012 14:50:17 +1000
    > From: Graham Cox <graham.cox...>
    > To: Samuel Williams <space.ship.traveller...>
    > Message-ID: <FCD6CCC5-8C3B-4C81-B1A6-98B0C1AD1B63...>
    >
    > Are you aware that this class is riddled with severe bugs under the current sandbox implementation?
    >
    > The dev forums will reveal more details.
    >
    > Also, NSSavePanel doesn't inherit from NSPanel under sandboxing, so if you are expecting to use inherited methods, they don't work.
    > ...
    > On 06/06/2012, at 1:41 PM, Samuel Williams wrote:
    >>
    >> I'm having trouble with NSSavePanel runModal in a sandbox:
    >>
    >> NSSavePanel * savePanel = [NSSavePanel savePanel];
    >> savePanel.title = @"Document Migration";
    >> savePanel.directoryURL = url;
    >> savePanel.nameFieldStringValue = [url lastPathComponent];
    >> savePanel.allowedFileTypes = [NSArray arrayWithObject:typeName];
    >> savePanel.message = @"Your document needs to be upgraded.";
    >>
    >> [savePanel setCanSelectHiddenExtension:YES];
    >> [savePanel setExtensionHidden:YES];
    >>
    >> NSInteger result = [savePanel runModal];

    I've had no problems at all with NSSavePanel under the sandbox (the inherited methods limitation that Graham mentioned excepted).

    My usage looks almost exactly like the code above except that I call -beginSheetModalForWindow:completionHandler: instead of -runModal.

    BUT. You need the com.apple.security.files.user-selected.read-write entitlement set to YES.

    HTH,
    --
    Rainer Brockerhoff  <rainer...>
    Belo Horizonte, Brazil
    "In the affairs of others even fools are wise
    In their own business even sages err."
    Weblog: http://www.brockerhoff.net/blog
  • >
    >
    > I've had no problems at all with NSSavePanel under the sandbox (the
    > inherited methods limitation that Graham mentioned excepted).
    >
    > My usage looks almost exactly like the code above except that I call
    > -beginSheetModalForWindow:completionHandler: instead of -runModal.
    >
    > BUT. You need the com.apple.security.files.user-selected.read-write
    > entitlement set to YES.
    >
    >
    Yeah, I have already set entitlements correctly. The NSPersistentDocument
    open/save are working fine. But, having issues with NSSavePanel... I tried
    the variation with completionHandler and still had the same problem, I also
    tried using a delegate but that also didn't seem to provide any useful
    information.

    Everything was working fine under a non-sandbox environment.. so its a bit
    odd..

    Maybe I could try to make a very minimal example that could be used for
    testing..

    Kind regards,
    Samuel
  • On Jun 8, 2012, at 11:20 AM, Samuel Williams <space.ship.traveller...> wrote:

    >>
    >>
    >> I've had no problems at all with NSSavePanel under the sandbox (the
    >> inherited methods limitation that Graham mentioned excepted).
    >>
    >> My usage looks almost exactly like the code above except that I call
    >> -beginSheetModalForWindow:completionHandler: instead of -runModal.
    >>
    >> BUT. You need the com.apple.security.files.user-selected.read-write
    >> entitlement set to YES.
    >>
    >>
    > Yeah, I have already set entitlements correctly. The NSPersistentDocument
    > open/save are working fine. But, having issues with NSSavePanel... I tried
    > the variation with completionHandler and still had the same problem, I also
    > tried using a delegate but that also didn't seem to provide any useful
    > information.
    >
    > Everything was working fine under a non-sandbox environment.. so its a bit
    > odd..
    >
    > Maybe I could try to make a very minimal example that could be used for
    > testing..

    If you are having trouble, definitely log a bug at bugreport.apple.com

    Even if it turns out to be something you might be doing wrong, we can update the documentation to better clarify the issue so others don't run into it.

    thanks!

    corbin
  • Hi Corbin + others,

    I wrote up my full experience including the solution I came up with on my
    blog here:
    http://www.codeotaku.com/blog/2012-06/sandboxing-core-data-and-migrations

    Please feel free to let me know if the code seems like a mistake. I filed a
    bug report

    Problem ID: 11544676: CoreData automatic migrations fail in sandbox.
    Problem ID: 11634243: NSSavePanel.URL is nil in sandbox

    Thanks to everyone for your help.

    Kind regards,
    Samuel

    On 9 June 2012 08:48, Corbin Dunn <corbind...> wrote:

    >
    > On Jun 8, 2012, at 11:20 AM, Samuel Williams <
    > <space.ship.traveller...> wrote:
    >
    >>>
    >>>
    >>> I've had no problems at all with NSSavePanel under the sandbox (the
    >>> inherited methods limitation that Graham mentioned excepted).
    >>>
    >>> My usage looks almost exactly like the code above except that I call
    >>> -beginSheetModalForWindow:completionHandler: instead of -runModal.
    >>>
    >>> BUT. You need the com.apple.security.files.user-selected.read-write
    >>> entitlement set to YES.
    >>>
    >>>
    >> Yeah, I have already set entitlements correctly. The NSPersistentDocument
    >> open/save are working fine. But, having issues with NSSavePanel... I
    > tried
    >> the variation with completionHandler and still had the same problem, I
    > also
    >> tried using a delegate but that also didn't seem to provide any useful
    >> information.
    >>
    >> Everything was working fine under a non-sandbox environment.. so its a
    > bit
    >> odd..
    >>
    >> Maybe I could try to make a very minimal example that could be used for
    >> testing..
    >
    > If you are having trouble, definitely log a bug at bugreport.apple.com
    >
    > Even if it turns out to be something you might be doing wrong, we can
    > update the documentation to better clarify the issue so others don't run
    > into it.
    >
    > thanks!
    >
    > corbin
    >
    >
previous month june 2012 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
Go to today