このコードを使用してImageMagickライブラリをアプリバンドルに入れようとしていますが、非常に複雑です。
-(id)init
{
if ([super init])
{
NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
NSString* imageMagickPath = [bundlePath stringByAppendingPathComponent:@"/Contents/Resources/ImageMagick"];
NSString* imageMagickLibraryPath = [imageMagickPath stringByAppendingPathComponent:@"/lib"];
MAGICK_HOME = imageMagickPath;
DYLD_LIBRARY_PATH = imageMagickLibraryPath;
}
return self;
}
-(void)composite
{
NSTask *task = [[NSTask alloc] init];
// the ImageMagick library needs these two environment variables.
NSMutableDictionary* environment = [[NSMutableDictionary alloc] init];
[environment setValue:MAGICK_HOME forKey:@"MAGICK_HOME"];
[environment setValue:DYLD_LIBRARY_PATH forKey:@"DYLD_LIBRARY_PATH"];
// helper function from
// http://www.karelia.com/cocoa_legacy/Foundation_Categories/NSFileManager__Get_.m
NSString* pwd = [Helpers pathFromUserLibraryPath:@"MyApp"];
// executable binary path
NSString* exe = [MAGICK_HOME stringByAppendingPathComponent:@"/bin/composite"];
[task setEnvironment:environment];
[task setCurrentDirectoryPath:pwd]; // pwd
[task setLaunchPath:exe]; // the path to composite binary
// these are just example arguments
[task setArguments:[NSArray arrayWithObjects: @"-gravity", @"center", @"stupid hat.png", @"IDR663.gif", @"bla.png", nil]];
[task launch];
[task waitUntilExit];
}
宣言DYLD_LIBRARY_PATH
とMAGICK_HOME
識別子(解決済み)
アップデート:
しかし、ビルドして実行しようとすると、アプリがクラッシュします。クラッシュ:[task launch];
。
コンソールメッセージ:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'working directory doesn't exist.'
どうすれば現在の問題を解決できますか?
更新2:
現在のコード:
- (id)initWithCoder:(NSCoder *)coder
{
NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
NSString* imageMagickPath = [bundlePath stringByAppendingPathComponent:@"/Contents/Resources/ImageMagick"];
NSString* imageMagickLibraryPath = [imageMagickPath stringByAppendingPathComponent:@"/lib"];
MAGICK_HOME = imageMagickPath;
DYLD_LIBRARY_PATH = imageMagickLibraryPath;
[self composite];
}
-(void)composite
{
NSTask *task = [[NSTask alloc] init];
NSMutableDictionary* environment = [[NSMutableDictionary alloc] init];
[environment setValue:MAGICK_HOME forKey:@"MAGICK_HOME"];
[environment setValue:DYLD_LIBRARY_PATH forKey:@"DYLD_LIBRARY_PATH"];
NSString* loc = [[NSString stringWithFormat:@"%@", MAGICK_HOME] retain];
NSString* exe = MAGICK_HOME;
[task setEnvironment:environment];
NSString* pwd = @"/opt/local/lib/";
[task setCurrentDirectoryPath:pwd];
[task setLaunchPath:loc];
NSLog(@"%@", loc);
NSLog(@"%@", pwd);
[task setArguments:[NSArray arrayWithObjects: @"-gravity", @"center", @"stupid hat.png", @"IDR663.gif", @"bla.png", nil]];
[task launch];
[task waitUntilExit];
}
そして現在のエラー(コンソール内):
*** NSTask: Task create for path '/Users/development/Library/Developer/Xcode/DerivedData/OGL-cahltqazoqxhrthkxztsqyvvodge/Build/Products/Debug/OGL.app/Contents/Resources/ImageMagick' failed: 22, "Invalid argument". Terminating temporary process.