iOS初始化资源包

资源包名:tam.zip   解压zip格式的文件所需要的第三方库:ZipArchive 下载链接:点击打开链接

#define GetFileInSites(file) [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/sites_25/%@",file]]


/**

 *  初始化程序资源文件  引用ZipArchive时 导入头文件:#import "ZipArchive.h"
 */
- (void)initResourcePacket{
    NSString *zipName = @"tam.zip";
    NSString *srcFilePath = [[NSBundle mainBundle] pathForResource:zipName ofType:nil];
    NSString *destPath = GetFileInSites(@"tam");
    
    if ([[NSFileManager defaultManager] fileExistsAtPath:destPath]) {
        NSLog(@"%s %@ 文件已经复制",__FUNCTION__,zipName);
        return;
    }
    if (![[NSFileManager defaultManager] fileExistsAtPath:srcFilePath]) {
        NSLog(@"!!!!       tam.zip 文件不存在           !!!!");
        return;
    }
    
    if (![[NSFileManager defaultManager] fileExistsAtPath:destPath]) {
        [[NSFileManager defaultManager] createDirectoryAtPath:destPath withIntermediateDirectories:YES attributes:nil error:nil];
        [GWManager addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:destPath]];
    }
    
    ZipArchive* zip = [[ZipArchive alloc] init];
    if( [zip UnzipOpenFile:srcFilePath] )
    {
        [zip UnzipFileTo:destPath overWrite:YES];
        [zip UnzipCloseFile];
    }
}



/**
 *  添加目录不备份属性
 *
 *  @param URL
 *
 *  @return
 */
+ (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);
    NSError *error = nil;
    BOOL success = [URL setResourceValue:[NSNumber numberWithBool: YES]
                                  forKey: NSURLIsExcludedFromBackupKey error: &error];
    if(!success){
        NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
    }
    return success;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值