-[NSWorkspace openApplicationAtURL:configuration:completionHandler:] error after startup

There is a LoginItem in my app that launches the application. It works fine with approximately the following code snippet:

    NSString *mainAppIdentifier = @"com.xxxxxxx";
    NSArray *runningApps = [[NSWorkspace sharedWorkspace]runningApplications];

    BOOL isRunning = NO;
    for (NSRunningApplication *application in runningApps) {
        if ([application.bundleIdentifier isEqualToString:mainAppIdentifier]) {
            isRunning = YES;
            break;
        }
    }

    if (!isRunning) {
        [[NSDistributedNotificationCenter defaultCenter]addObserver:self selector:@selector(terminate) name:@"killLauncher" object:mainAppIdentifier];

        NSString *path = [[NSBundle mainBundle]bundlePath];
        NSMutableArray *components = [NSMutableArray arrayWithArray:path.pathComponents];
        [components removeLastObject];
        [components removeLastObject];
        [components removeLastObject];
        [components addObject:@"MacOS"];
        [components addObject:@"appName"];

        NSString *newPath = [NSString pathWithComponents:components];
        [[NSWorkspace sharedWorkspace]launchApplication:newPath];

Since 11.0, launchApplication: is deprecated in favour of openApplicationAtURL:. When I try to modify it and restart the device, the following error appears:

Application "xxx" does not have permission to open "xxxx"

How should I do

-[NSWorkspace openApplicationAtURL:configuration:completionHandler:] error after startup
 
 
Q