- (void)checkSDKAds:(NSString *)appId version:(NSString *)version withCompletion:(void(^)(BOOL isShow, NSDictionary *dict))completion{
NSString *str = [NSString stringWithFormat:@"http://api.zhiphone.com.cn/DynamicCDN/ConfigParam.html?appid=%@&version=%@&mid=",appId,version];
[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:5] queue:[NSOperationQueue new] completionHandler:^(NSURLResponse *res, NSData *data, NSError *error) {
if (error == nil&&data!=nil)
{
NSString *json = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if ([json isEqualToString:@"-10000"]){
return ;
}
NSDictionary *parserToArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
[json release];
BOOL isShow = YES;
//AppID 不为空则显示广告
if ([parserToArray objectForKey:@"AppID"]==nil) {
isShow =NO;
}
if (completion) {
dispatch_async(dispatch_get_main_queue(), ^{
completion(isShow,parserToArray);
});
}
}else{
dispatch_async(dispatch_get_main_queue(), ^{
completion(NO,[NSDictionary dictionary]);
});
}
}];
}
//使用方法,填写自己的sdkId。版本
[self checkSDKAds:@"11116" version:@"1.0" withCompletion:^(BOOL isShow, NSDictionary *dict) {
if (isShow) {
NSLog(@"%@",dict);
//添加自己的业务逻辑
}
}];
分享一个使用方法,镜子sdk里的。获取到数据会显示下载按钮,否则不显 |