Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 应用程序崩溃,除非从Xcode运行_Objective C_Xcode_Macos_Applescript - Fatal编程技术网

Objective c 应用程序崩溃,除非从Xcode运行

Objective c 应用程序崩溃,除非从Xcode运行,objective-c,xcode,macos,applescript,Objective C,Xcode,Macos,Applescript,我有以下代码: NSColor *color = [NSColor colorWithDeviceHue:hue saturation:saturation brightness:brightness alpha:1.0]; NSString *scriptString = [NSS

我有以下代码:

NSColor *color = [NSColor colorWithDeviceHue:hue
                                  saturation:saturation
                                  brightness:brightness
                                       alpha:1.0];

NSString *scriptString = [NSString stringWithFormat:
                            @"try\n"
                                @"tell application \"Adobe Photoshop CS5\" \n"
                                    @"set foreground color to {class:RGB color, red:%f, green:%f, blue:%f} \n"
                                @"end tell\n"
                            @"on error\n"
                                @"try\n"
                                    @"tell application \"Adobe Photoshop CS4\" \n"
                                        @"set foreground color to {class:RGB color, red:%f, green:%f, blue:%f} \n"
                                    @"end tell\n"
                                @"end try\n"
                            @"end try",
                            [color redComponent] * 255,
                            [color greenComponent] * 255,
                            [color blueComponent] * 255];
NSLog(@"script string: %@", scriptString);

NSAppleScript *script = [[NSAppleScript alloc] initWithSource:scriptString];
NSDictionary *error;
[script executeAndReturnError:&error];
NSLog(@"result: %@", error);
当我从xcode的运行特性运行它时,它运行得很好。当我将它构建为一个应用程序并独立运行时,它在这一部分经常崩溃

知道为什么会这样吗

编辑:大部分崩溃日志(不能全部放在这里)


最常见的错误是:NSAppleScript,因为它共享一个AppleScript组件实例。但是,如果您显示崩溃日志,它会有所帮助。

您首先需要将
错误设置为零:

NSDictionary *error = nil;

[script executeAndReturnError:&error]
只有在失败时才会更改
error
的值。这就是为什么在没有错误的情况下,您会得到一个错误的访问。

编辑为包含崩溃日志。如果尚未在主线程上运行,如何确保它在主线程上运行?可能,您在这行代码[StatusMenuItemSampleAppDelegate didReceiveMessage:+1023(StatusMenuItemSampleAppDelegate.m:294)中遇到了一些零或其他问题,您在此处调用了NSLog函数,检查it参数。根据崩溃日志,代码正在主线程上运行。这是不正确的。必须检查方法的直接返回值以确定是否发生错误。在Cocoa中,如果没有发生错误,则不能保证错误指针保持为
nil
NSDictionary *error = nil;