0

重複の可能性:
NSTask起動パスにアクセスできません

なぜこれを呼ぶのか、

NSTask *buildMTask = [[NSTask alloc] init];
[buildMTask setLaunchPath:@"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\\ Simulator.app/Contents/MacOS/iPhone\\ Simulator"];
[buildMTask launch];

結果は

「起動パスにアクセスできません」?

ありがとう!

4

1 に答える 1

1
NSString *appname = @"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator";
NSTask *aTask = [[NSTask alloc] init];
[aTask setLaunchPath:appname];
BOOL exists = [[NSFileManager defaultManager] isExecutableFileAtPath:[aTask launchPath]];
NSLog(@"%@ '%@'\n", exists ? @"Exists" : @"Does Not Exist", [aTask launchPath]);
[aTask launch];

実行可能ファイルが存在することをログに記録しても、正しく動作します。\\実行可能ファイル名から をすべて削除します。

アプリを実行する前に、実行可能ファイルの存在チェックを使用することをお勧めします。

于 2012-10-17T17:26:20.273 に答える