2011-01-10 52 views
0

我已經看到writeToFile不能用於非對象的解釋, 但是,這段代碼顯示iPad上的工作方式存在嚴重的缺陷設備 以及模擬器如何工作。objective-c writeToFile不在iPad上,在模擬器上

NSMutableArray *arrayOne = [NSMutableArray arrayWithObjects:@"Thing One", @"Thing Two", @"Thing Three", nil]; 
[arrayOne writeToFile:@"myLocalMovieMetaData-v11" atomically:YES]; 
NSLog(@"cancelNowButton Test Metadata File Written."); 
NSMutableArray *arrayTwo = [NSMutableArray arrayWithContentsOfFile:@"myLocalMovieMetaData-v11"]; 
NSLog(@"arrayOne: %@",arrayOne); 
NSLog(@"arrayTwo: %@",arrayTwo); //this prints on simulator but not the device. 

回答

3

應用程序只具有寫權限的Documents目錄:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myLocalMovieMetaData-v11"]; 

然後使用:

[arrayOne writeToFile:path atomically:YES]; 
+0

這也正是問題。 (你打我幾秒鐘。)到OP,檢查你的硬盤驅動器的根。你會發現在那裏創建了「myLocalMovieMetaData-v11」文件。 – 2011-01-10 23:25:20

相關問題