123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- /**
- */
- #import "ADView.h"
- #import "UIImageView+WebCache.h"
- /**并不是要保留ADView内存。
- 而是。在系统进入后台后,要添加ADView。
- 在becomeActive里面。计时2秒移除。
- */
- static ADView* mainAD;
- @interface ADView()
- @property(nonatomic,strong) NSMutableArray* ivs;
- @end
- @implementation ADView
- +(void)showADView
- {
- if (!defUser.adPaths || defUser.adPaths.count <1) {
- [ADView loadADPaths];
- return;
- }
-
- mainAD = [[ADView alloc] initWithFrame:kFrame];
- UIWindow* window = [UIApplication sharedApplication].keyWindow;
- dispatch_after(1, dispatch_get_main_queue(), ^{
- [window addSubview:mainAD];
- [mainAD performSelector:@selector(removeImidiate) withObject:nil afterDelay:3];
- });
- }
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- self.userInteractionEnabled = YES;
- [self setImage:[UIImage imageNamed:@"LaunchImage.png"]];
- [self setContentMode:UIViewContentModeScaleAspectFill];
-
- NSString *path = defUser.adPaths[arc4random()%defUser.adPaths.count];
- UIImageView* iv = [[UIImageView alloc] initWithFrame:kFrame];
- //iv.height -= kSize.height*.25;
-
- if (!path) {
- path = @"";
- }
- [iv sd_setImageWithURL:[NSURL URLWithString:path] placeholderImage:[UIImage imageNamed:@"firstAD"]];
- [self addSubview:iv];
-
- UIButton *skipBtn = [[UIButton alloc]
- initWithFrame:CGRectMake(kSize.width - 55, kStatusHeight+5, 35, 35)];
- skipBtn.backgroundColor = [UIColor darkGrayColor];
- UIColor *newcolor = [UIColor whiteColor];
- [skipBtn setTitle:@"跳过" textColor:newcolor font:Font16 fotState:UIControlStateNormal];
- skipBtn.titleLabel.font = [UIFont systemFontOfSize:14];
- skipBtn.layer.masksToBounds = YES;
- skipBtn.layer.cornerRadius = 35/2;
- skipBtn.layer.borderWidth = 1.0;
- skipBtn.layer.borderColor = newcolor.CGColor;
- [skipBtn addTarget:self action:@selector(removeImidiate) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:skipBtn];
- }
- return self;
- }
- +(void)removeADView
- {
- if (!mainAD) {
- return;
- }
- [mainAD performSelector:@selector(removeImidiate) withObject:nil afterDelay:2];
- }
- -(void)removeImidiate
- {
-
- if (self.superview) {
- [UIView animateWithDuration:.5 animations:^{
- self.alpha = 0;
- } completion:^(BOOL finished) {
- [self removeFromSuperview];
- mainAD = nil;
- }];
- }
- }
- void loadADPaths(){
- [ADView loadADPaths];
- }
- /**下载工作可以在每次will进入后台时。调用?
- 但其实这个东西不怎么耗时。真正耗时的是加载图片。
- */
- +(void)loadADPaths
- {
- if (![Util connectedToNetWork]) {
- return ;
- }
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"type" Value:@"4"];
-
- NSString* method = @"getAppAdsNew";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
- RemoveHUD();
-
- if (!dict) {
- return ;
- }
- if ( [dict[@"code"] isEqualToString:@"1"]) {
- return ;
- }
- NSArray* body = dict[@"body"];
- [arr removeAllObjects];
- for (NSDictionary *dic in body) {
- if ([dic[@"LOCATION"] isEqualToString:@"11"]) {
- [arr addObject:[dic objectForKey:@"IMG"]];
- }
- }
- defUser.adPaths = arr;
- }];
- }
- @end
|