2010-06-28 67 views
0

確定,eXercice即將獲得到正在運行的應用程序我有這樣做的路徑:問題的複製主要應用

NSFileManager *FManager = [ NSFileManager defaultManager ] ; 
NSString *CurrentPath = [ FManager currentDirectoryPath ] ; 
NSDictionary *infoPList = [[NSBundle mainBundle] infoDictionary]; 
NSString *appName = [infoPList objectForKey:@"CFBundleName"]; 
NSString *mainpath = [ CurrentPath stringByAppendingPathComponent:appName ] ; 
NSString *mainFile = [ mainpath stringByAppendingString:@".app" ] ; 

然後我嘗試將主文件複製到主目錄

NSString *homedir = NSHomeDirectory(); 
if ([ Fmanager fileExistsAtPath:mainfile ] == YES) 
    NSLog(@" File exist ") ; 
else { 
    NSLog(@" not eXist "); 
} 

if ([ Fmanager copyItemAtPath:mainfile toPath:homedir error:NULL ] == YES) { 
    NSLog(@" COPY SUCC ") ; 
} 
else { 
    NSLog(@" COPY FAIL") ; 
} 

這裏複製過程失敗,它也告訴我,主文件甚至不eXists ... ou 任何人都可以幫我請 謝謝。

+0

下次格式化您的代碼。 – 2010-06-28 16:18:42

回答

0

除非您只設置它,否則依賴當前目錄的值通常是一個糟糕的主意。無論如何,你讓它太難了。該應用程序的路徑將是[[NSBundle mainBundle] bundlePath]

+0

Thnx,但我不明白這裏是[[NSBundle mainbundle] executablepath]應該返回到主要可執行文件的路徑,它不是這種情況,它返回給我: /用戶/ mayname /庫/應用程序支持/ iPhone Simulator/4.0/Applications/9FAA4D2E-D826-42D9-B068-D0B715064C59/Testme.app/Testme 有人可以向我解釋這個,以及我應該使用Bundlepath或executablePath? 謝謝 – Archer 2010-06-29 10:30:28

+0

這是主要可執行文件的路徑。 – 2010-06-29 13:05:03

1

通過主文件,你的意思是主要的可執行文件?查看NSBundle以獲取已編譯應用程序的各種組件的路徑。

[[NSBundle mainBundle] bundlePath]; // path to your.app 
[[NSBundle mainBundle] executablePath]; // path to your.app main executable