【发布时间】:2013-11-08 13:16:14
【问题描述】:
代码可以 100% 运行,但是在切换到 iOS7 和 XCode 5 后,我无法使用 NSFilemanager 方法获取文件的路径,代码无法找到 timetableXML 文件和触发器的路径 -> else @"NO这样的文件存在”,这里有代码:
- (void)viewDidLoad
{
[super viewDidLoad];
APUAppDelegate *appDelegate = (APUAppDelegate *)[[UIApplication sharedApplication]delegate];
context = [appDelegate managedObjectContext];
dispatch_queue_t queue = dispatch_get_global_queue(0,0);
dispatch_async(queue, ^{
NSLog(@"Beginning download");
NSString *stringURL = @"http://webspace.apiit.edu.my/intake-timetable/download_timetable/timetableXML.zip";
NSURL *url = [NSURL URLWithString:stringURL];
NSData *urlData = [NSData dataWithContentsOfURL:url];
NSLog(@"Got the data!");
//Find a cache directory. You could consider using documenets dir instead (depends on the data you are fetching)
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
//Save the data
NSLog(@"Saving");
dataPath = [path stringByAppendingPathComponent:@"timetableXML.zip"];
dataPath = [dataPath stringByStandardizingPath];
[urlData writeToFile:dataPath atomically:YES];
/////////////////// TEST
// Existence of the xml file
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *pathToMyFile = [path stringByAppendingPathComponent:@"timetableXML.zip"];
if ([fileManager fileExistsAtPath:pathToMyFile]) {
// file exists
NSLog(@"YES a file exist with ZIP extension");
NSLog(@"Unziped successfully!");
path1 = pathToMyFile;
[self unzipFile:path1];
}
else {
NSLog(@"NO such a file exist");
}
});
}
【问题讨论】:
标签: iphone objective-c cocoa-touch ios7