程序员

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

2017-08-04  本文已影响0人  有梦想de咸鱼

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


-(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];
    }
}

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

上一篇 下一篇

猜你喜欢

热点阅读