我有一个应用程序,其中包含需要添加到NSMutableArray中的路径,以及writeToFile它。
int r = arc4random() % 100;
int s = arc4random() % 100;
int e = arc4random() % 100;
NSLog(@"%i%i%i.MOV", r, s, e);
NSString * tempFileName = [NSString stringWithFormat:@"%i%i%i.MOV", r, s, e];
NSString * tempFilePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
NSString * documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString * storePath = [documentsDirectory stringByAppendingPathComponent:tempFileName];
NSError *error = nil;
[[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:tempFilePath]
toURL:[NSURL fileURLWithPath:storePath]
error:&error];
if (error) {
NSLog(@"%@", error);
}
NSLog(@"Old File path : %@", tempFilePath);
NSLog(@"New File path : %@", storePath);
dayCounter ++;
videoDayCounter = [[NSMutableArray alloc] initWithContentsOfFile:dayCounterPath];
NSLog(@"DayCounter INIT");
[videoDayCounter addObject:dayCounter];
[videoDayCounter writeToFile:dayCounterPath atomically:YES];
NSLog(@"dayCounter wrote to file"); '
allVideos = [[NSMutableArray alloc] initWithContentsOfFile:allVideosPath];
NSLog(@"AllVideosINIT");
[allVideos addObject:storePath];
NSLog(@"array: %@", allVideos);
[allVideos writeToFile:allVideosPath atomically:YES];
[videoCount setText:[allVideos count]];
[daysLabel setText:[videoDayCounter count]];
[self dismissModalViewControllerAnimated:YES];
[picker release];
所有视频的NSLog都返回NULL。
我试图通过
在应用启动时创建allVideosPath NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *allVideosPath = [documentsDirectory stringByAppendingPathComponent:@"allVideos.plist"];
NSString *dayCounterPath = [documentsDirectory stringByAppendingPathComponent:@"dayCount.plist"];
BOOL booleanAllVideos;
BOOL booleanDayCounter;
NSFileManager *fileManager = [NSFileManager defaultManager];
booleanAllVideos = [fileManager fileExistsAtPath:allVideosPath];
booleanDayCounter= [fileManager fileExistsAtPath:dayCounterPath];
if(booleanAllVideos == NO)
{
NSMutableArray *allVideos = [[NSMutableArray alloc] initWithCapacity:3];
[allVideos writeToFile:allVideosPath atomically:YES];
}
if(booleanDayCounter == NO)
{
NSMutableArray *videoDayCounter = [[NSMutableArray alloc] initWithCapacity:3];
[allVideos writeToFile:dayCounterPath atomically:YES];
}
但我猜它不起作用?
谢谢!
答案 0 :(得分:0)
[[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:tempFilePath]
toURL:[NSURL fileURLWithPath:storePath]
error:&error];
你确定文件“tempFilePath”存在吗?
答案 1 :(得分:0)
在您的阅读功能中,allVideosPath
是否正确定义?我没有看到任何代码在你的阅读功能中设置它。