我正在使用以下代码下载slqite文件并存储它
self.responseData = NSMutableData我收到responseData = 2048bytes。工作得很好。
然而,白写它确实创建了一个文件myFile.sqlite,但它是零字节的。怎么啦?
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *dbPath = [self getDBPath];
BOOL success = [fileManager fileExistsAtPath:dbPath];
if(!success)
{
if(self.responseData)
{
dbPath = [dbPath stringByAppendingPathComponent:[self.selectedBtn.dbPath lastPathComponent]];
[self.responseData writeToFile:dbPath atomically:YES];
[self performSegueWithIdentifier:@"list" sender:self];
}
}
[self.alertView removeFromSuperview];
}
-(NSString *) getDBPath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSURL *url = [[NSURL alloc] initWithString:[self.selectedBtn.dbPath lastPathComponent]];
return [documentsDir stringByAppendingPathComponent:[url lastPathComponent]];
}我收到错误消息
`The operation couldn’t be completed. (Cocoa error 4.)`
dbPath : /Users/umar/Library/Application Support/iPhone Simulator/6.1/Applications/00027635-CE9C-48C3-8000-64CA1E6532F1/Documents/music.sqlite/music.sqlite发布于 2013-03-15 04:12:24
您添加了两次[self.selectedBtn.dbPath lastPathComponent],一次是在getDBPath中,另一次是ion connctionDidFinishLoading。
选择要删除的其中一个实例。
发布于 2013-03-15 04:10:52
Documents/music.sqlite/music.sqlite不,这不是一个有效的路径...你是说Documents/music.sqlite,是不是?还有,我不明白你为什么为了一个无关的任务而强奸可怜的NSURL。
return [documentsDir stringByAppendingPathComponent:[self.selectedBtn.dbPath lastPathComponent]];此外,确保self.selectedBtn.dbPath也确实是一个有效的路径,而不是垃圾(我可以想象它是)。
https://stackoverflow.com/questions/15418857
复制相似问题