IOS文件下载

 NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  NSUserDomainMask,YES);//使用C函数NSSearchPathForDirectoriesInDomains来获得沙盒中目录的全路径。

    

//  ***  NSString * documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

    

    NSString *ourDocumentPath =[documentPaths objectAtIndex:0];

    NSString *sandboxPath = NSHomeDirectory();

//    NSString *documentPath = [sandboxPath  stringByAppendingPathComponent:@"Purchase.app"];//将Documents添加到sandbox路径上//stringByAppendingPathComponent

    NSString *FileName=[ourDocumentPath stringByAppendingPathComponent:_fileName];//fileName就是保存文件的文件名

    

    NSLog(FileName);

    NSFileManager *fileManager = [NSFileManager defaultManager];

    // Copy the database sql file from the resourcepath to the documentpath

    if ([fileManager fileExistsAtPath:FileName])

    {

        return FileName;

    }else

    {

        NSURL *url = [NSURL URLWithString:fileUrl];

        NSData *data = [NSData dataWithContentsOfURL:url];

        [data writeToFile:FileName atomically:YES];//将NSData类型对象data写入文件,文件名为FileName

    }

    return FileName;

posted @   小毛驴  阅读(185)  评论(0编辑  收藏  举报
编辑推荐:
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
· .NET 适配 HarmonyOS 进展
阅读排行:
· 如何给本地部署的DeepSeek投喂数据,让他更懂你
· 超详细,DeepSeek 接入PyCharm实现AI编程!(支持本地部署DeepSeek及官方Dee
· 用 DeepSeek 给对象做个网站,她一定感动坏了
· .NET 8.0 + Linux 香橙派,实现高效的 IoT 数据采集与控制解决方案
· .NET中 泛型 + 依赖注入 的实现与应用
点击右上角即可分享
微信分享提示