NSOpenPanel does not work and the application becomes “not responding”.

The code below does not work properly in macos sonoma. I tested it on multiple Macs (mini, m1, intel), but it does not work the same way. (Normal operation in sonoma preview version and previous versions)

NSOpenPanel* openPanel = [NSOpenPanel openPanel]

Symptoms:

When you press the button, the cursor changes to a whirlwind icon. My application and another system service (openAndSavePanelService) become "Not Responding".

However, after a few minutes, this condition is resolved and my application returns to normal, but openAndSavePanelService continues to be in the "Not Responding" state.

Suppose:

Looking at the attached spindump, it is assumed that when openPanel init is called, a problem occurs in the process of communicating with xpc and the system service (openAndSavePanelService) for displaying the dialog box.

What I tried:

  1. Without creating an instance when pressing the button NSOpenPanel* g_openPanel = [NSOpenPanel openPanel] When the task is attempted in main and the button is pressed, openPanel was attempted with the created instnace, but failed.

  2. Tried to work with NSOpenPanel* g_openPanel = [NSOpenPanel openPanel] via dispatch_async(dispatch_get_main_queue(), { ... }) but failed.

I found similar questions on forums but they didn't help. https://developer.apple.com/forums/thread/104442?answerId=332068022#332068022

Project environment:

  • Cocoa project
  • Application is agent(UIElement)
  • Hardened Runtime (apple event checked)
  • No Sandbox
  • Network Extension
  • System Extension
  • Deployment Target: 10.9

Could it be a permission issue? Is there anything else worth trying?

Do you see the same problem if you create a new project from the macOS > App template. Here’s what I did:

  1. Using Xcode 15.0 on macOS 14.1.2, I created a new test project from the macOS > App template, selecting Storyboard and Objective-C as the options.

  2. I added the code below to ViewController.m.

    - (IBAction)testAction:(id)sender {
        NSOpenPanel * openPanel = [NSOpenPanel openPanel];
        NSLog(@"%@", openPanel);
    }
    
  3. In Main.storyboard, I wired a button up to that action.

  4. I choose Product > Run.

  5. In the app, I clicked my button. The app promptly printed:

    <NSOpenPanel: 0x110e07000>
    

Please try this on your Mac and let us know what you see.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

As a result of testing the code you mentioned, you can see the log below. (In fact, when I already created and tested a statusbar project similar to the current project, NSOpenPanel worked normally)

<NSOpenPanel: 0x132351ed0>

And the link below is the spindump.txt file when "no response" occurs.

http://gofile.me/3ybqZ/JhLSuHzId

I'm sorry. The link is incorrect. Please refer to the link below.

http://gofile.me/3ybqZ/v09Gs3SZi

So, a newly created test app works but your app is failing. Right?

Looking at your spin dump I see that the hung app is running under Rosetta. If you adjust your test app to run under Rosetta, how does it behave?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

you're right. Only my application fails.

"If you adjust your test app to run under Rosetta," I'm not sure exactly what it means, but

This spindump failed on an m1 mac, but actually also failed on an i5 (intel) mac. (no under rosetta)

Is my assumption below correct?

myapp openPanel -> xpc -> openAndSaveService A failure occurred while myapp was waiting for a signal from openAndSaveService.

NSOpenPanel does not work and the application becomes “not responding”.
 
 
Q