文件存在或未检查在ios中不起作用?
您好,我正在使用以下代码检查文件是否存在于我的文档目录中,但它看起来好像不工作。当我在wifi中运行应用程序时,它将下载plist文件并保存在文档目录中,当我强制关闭该应用程序并关闭wifi后,再次运行,那么它不会检测文档目录中已经存在的文件 这是我的密码文件存在或未检查在ios中不起作用?,ios,file,storyboard,plist,nsfilemanager,Ios,File,Storyboard,Plist,Nsfilemanager,您好,我正在使用以下代码检查文件是否存在于我的文档目录中,但它看起来好像不工作。当我在wifi中运行应用程序时,它将下载plist文件并保存在文档目录中,当我强制关闭该应用程序并关闭wifi后,再次运行,那么它不会检测文档目录中已经存在的文件 这是我的密码 NSString *filename=@"Form.plist"; NSString *filecomponent=[NSString stringWithFormat:@"%@",filename]; NSStr
NSString *filename=@"Form.plist";
NSString *filecomponent=[NSString stringWithFormat:@"%@",filename];
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:filecomponent];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:filePath];
if(!fileExists){
if([Connectivity hasConnectivity])
{
//Download file again
// NSLog(@"%@",[[config objectForKey:@"URL"]valueForKey:@"Form"]);
[self downloadFile:[[config objectForKey:@"URL"]valueForKey:@"Form"] :filename :identifier :rb];
}else{
alert=[[UIAlertView alloc]initWithTitle:@"Alert" message:@"Please check your internet connectivity." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
}else{
rb = [self.storyboard instantiateViewControllerWithIdentifier:@"Form"];
[self.navigationController pushViewController:rb animated:YES];
}
如果现在没有internet,它只显示警报,而不是进入内部查看控制器。将Form.plist文件移动到应用程序包中。然后尝试使用“[[NSBundle mainBundle]pathForResource:@formoftype:@plist];”,将其分配给您的文件路径字符串。@Karthik sivam我们无法将文件写入NSBundle。。它受Apple自身的限制。您的文件路径正确吗?尝试打印出来。@user2990885您当然不能写,但您可以将其移动或手动添加到应用程序包中。chancy:谢谢…路径为空…这就是问题所在