IOS 编译后代码修改mainBundle的文件的可行性

因为需求问题,今天测试了一下运行后,代码改变mainBundle里边文件的操作,发现一下情况


  • 将两张不同名字的图片拖入工程(testImage和testImage2),核心代码如下:
-(void)replaceImage{
    NSString *testImagePath = [[NSBundle mainBundle] pathForResource:@"testImage" ofType:@"png"];
    NSString *testImage2Path = [[NSBundle mainBundle] pathForResource:@"testImage2" ofType:@"png"];
    NSLog(@"%@",testImage2Path);
    BOOL success = [FILE_MANAGER replaceItemAtURL:[NSURL fileURLWithPath:testImagePath] withItemAtURL:[NSURL fileURLWithPath:testImage2Path] backupItemName:@"testImage.png" options:NSFileManagerItemReplacementUsingNewMetadataOnly resultingItemURL:nil error:nil];
    if (success) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"tips" message:@"替换成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}
  • 结果发现,在模拟机下是能替换的,但是,在真机下是不行的。然后拿了一些调试证书打出来的ipa包解压修改里边的文件,发现也是做了校验的:


    安装图片

所以不用打编译后的mainBundle的文件的注意了,毕竟安全很重要

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容