Tag: bundle

  • iOS: 尋找模擬器的暫存路徑

    在 iOS APP 的開發過程,大量依賴 Xcode 內建的模擬器來做雛型的測試。其中也需要知道文件的狀態變化是否如預期一般運作。 但是模擬器的文件暫存路徑會有一組 UID 亂數,當手上的專案一多就分不出來是哪個資料夾了。可以用以下方法取得該 App 的文件路徑。 NSLog(@”%@”, [[NSBundle mainBundle] bundlePath]); 結果如下: /Users/filework/Library/Application Support/iPhone Simulator/6.1/Applications/642CB434-53D0-440A-9BB4-A5E1801D36EE/qxFMDB.app 若要列出目錄下的檔案,用以下方法。 NSFileManager *fm=[NSFileManager defaultManager]; NSString *path=[[NSBundle mainBundle]bundlePath]; NSArray *info=[fm contentsOfDirectoryAtPath:path error:nil]; NSLog(@”list:%@”,info); 執行結果如下: list:( “Default-568h@2x.png”, “Default.png”, “Default@2x.png”, “en.lproj”, “Info.plist”, “Main.storyboardc”, PkgInfo )  

Exit mobile version