我使用此代碼來告訴我的第二類將文件保存到指定路徑的路徑:保存到路徑沒有工作,除非我讓用戶選擇
if ([defaults boolForKey:@"SaveAutomatically"]) {
basepath = [defaults objectForKey:@"SaveAutomaticallyPath"];
basepath = [basepath stringByAppendingPathComponent:[defaults objectForKey:@"SaveAutomaticallyName"]];
}
[NSThread detachNewThreadSelector:@selector(saveTo:) toTarget:controller withObject:basepath];
所以,saveTo:
方法被調用。它首先檢查給出的路徑是好的
if (![[[aPath pathExtension] lowercaseString] isEqualToString:@"icns"]) {
aPath = [aPath stringByAppendingPathExtension:@"icns"];
}
if ([[NSFileManager defaultManager] fileExistsAtPath:aPath]) {
[delegate error:@"File exists already."];
[self performSelectorOnMainThread:@selector(fs)
withObject:nil waitUntilDone:NO];
}
然後做一些事情,並創建一個CGImageDestinationRef
:
NSURL *fileURL = [NSURL fileURLWithPath:aPath];
CGImageDestinationRef dr = CGImageDestinationCreateWithURL((CFURLRef)fileURL, kUTTypeAppleICNS , count, NULL);
if (!dr) {
[delegate error:@"Unable to save icon file."];
[self performSelectorOnMainThread:@selector(fs)
withObject:nil waitUntilDone:NO];
return;
}
dr
是零每次。如果我通過使用NSSavePanel
給saveTo
一條路徑,它不會抱怨並且工作正常。 我試着登錄saveTo:
的路徑,但工作正常(例如,/Users/Home/Desk/Results.icns)。
換句話說,當上面的代碼保存到/Users/Home/Desktop/Result.icns失敗了,但是當我讓用戶決定保存到使用NSSavePanel
相同的路徑,沒有任何問題。
我正在使用SandBoxing。我該如何解決這個問題?
好吧,有道理。謝謝!!! – Fatso