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包解压修改里边的文件,发现也是做了校验的:


    IOS 编译后代码修改mainBundle的文件的可行性_第1张图片
    安装图片

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

你可能感兴趣的:(IOS 编译后代码修改mainBundle的文件的可行性)