天天看點

iOS 防止二次打包 筆記

// 校驗值,可通過上一次打包擷取
#define PROVISION_HASH @"Mfx1YZk7hZShm/IyV1QLWdogSQM="
static NSDictionary *rootDic=nil;

void checkSignatureMsg()
{
    NSString *newPath = [[NSBundle mainBundle] resourcePath];

    if (!rootDic) {
        rootDic = [[NSDictionary alloc] initWithContentsOfFile:[newPath stringByAppendingString:@"/_CodeSignature/CodeResources"]];
    }

    NSDictionary *fileDic = [rootDic objectForKey:@"files2"];
    NSDictionary *infoDic = [fileDic objectForKey:@"embedded.mobileprovision"];
    NSData *tempData = [infoDic objectForKey:@"hash"];
    NSString *hashStr = [tempData base64EncodedStringWithOptions:0];
    if (![PROVISION_HASH isEqualToString:hashStr]) {
        abort();//退出應用
    }
}