iOS防止抓包

weixin_33766168發表於2018-11-08

#pragma mark - 初步方案,判斷是否設定代理,如果設定了代理就視為在抓包

- (BOOL)getProxyStatus {

    NSDictionary*proxySettings =  (__bridgeNSDictionary*)(CFNetworkCopySystemProxySettings());

    NSArray *proxies = (__bridge NSArray *)(CFNetworkCopyProxiesForURL((__bridge CFURLRef _Nonnull)([NSURL URLWithString:@"http://www.baidu.com"]), (__bridge CFDictionaryRef _Nonnull)(proxySettings)));

    NSDictionary*settings = [proxiesobjectAtIndex:0];


    NSLog(@"host=%@", [settingsobjectForKey:(NSString*)kCFProxyHostNameKey]);

    NSLog(@"port=%@", [settingsobjectForKey:(NSString*)kCFProxyPortNumberKey]);

    NSLog(@"type=%@", [settingsobjectForKey:(NSString*)kCFProxyTypeKey]);


    if([[settingsobjectForKey:(NSString*)kCFProxyTypeKey]isEqualToString:@"kCFProxyTypeNone"]){

        //沒有設定代理

        returnNO;

    }else{

        //設定代理了


        returnYES;

    }

}

相關文章