Skip to content

Commit 29bdd5b

Browse files
committed
v3.6.1 - 1.增加清除指定图片/视频缓存接口,2.优化在iPhoneX上显示效果,3.已知问题优化与修复...
1 parent ca79690 commit 29bdd5b

File tree

12 files changed

+165
-34
lines changed

12 files changed

+165
-34
lines changed

Class/WebViewController.m

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,37 @@
99

1010
#import "WebViewController.h"
1111
#import <WebKit/WebKit.h>
12+
#import "XHLaunchAd.h"
13+
1214
@interface WebViewController ()
1315
@property(nonatomic,strong)WKWebView *webView;
1416
@property (nonatomic, strong) UIProgressView *progressView;
1517
@end
1618

1719
@implementation WebViewController
1820

21+
-(void)dealloc
22+
{
23+
/**
24+
如果你设置了APP从后台恢复时也显示广告,
25+
当用户停留在广告详情页时,APP从后台恢复时,你不想再次显示启动广告,
26+
请在广告详情控制器销毁时,发下面通知,告诉XHLaunchAd,广告详情页面已显示完
27+
*/
28+
[[NSNotificationCenter defaultCenter] postNotificationName:XHLaunchAdDetailPageShowFinishNotification object:nil];
29+
30+
[self.webView removeObserver:self forKeyPath:@"estimatedProgress"];
31+
}
32+
-(void)viewWillAppear:(BOOL)animated
33+
{
34+
[super viewWillAppear:animated];
35+
36+
/**
37+
如果你设置了APP从后台恢复时也显示广告,
38+
当用户停留在广告详情页时,APP从后台恢复时,你不想再次显示启动广告,
39+
请在广告详情控制器将要显示时,发下面通知,告诉XHLaunchAd,广告详情页面将要显示
40+
*/
41+
[[NSNotificationCenter defaultCenter] postNotificationName:XHLaunchAdDetailPageWillShowNotification object:nil];
42+
}
1943
- (void)viewDidLoad {
2044
[super viewDidLoad];
2145
self.navigationItem.title = @"详情";
@@ -38,6 +62,11 @@ - (void)viewDidLoad {
3862
self.progressView.progressTintColor = [UIColor blackColor];
3963
[self.navigationController.view addSubview:self.progressView];
4064
}
65+
-(void)viewWillDisappear:(BOOL)animated
66+
{
67+
[super viewWillDisappear:animated];
68+
[self.progressView removeFromSuperview];
69+
}
4170
-(void)back{
4271

4372
if([_webView canGoBack])
@@ -49,13 +78,6 @@ -(void)back{
4978
[self.navigationController popViewControllerAnimated:YES];
5079
}
5180
}
52-
53-
-(void)viewWillDisappear:(BOOL)animated
54-
{
55-
[super viewWillDisappear:animated];
56-
[self.progressView removeFromSuperview];
57-
}
58-
5981
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context{
6082
if ([keyPath isEqualToString:@"estimatedProgress"]) {
6183

@@ -73,10 +95,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
7395
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
7496
}
7597
}
76-
- (void)dealloc{
77-
78-
[self.webView removeObserver:self forKeyPath:@"estimatedProgress"];
79-
}
98+
8099
- (void)didReceiveMemoryWarning {
81100
[super didReceiveMemoryWarning];
82101
// Dispose of any resources that can be recreated.

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
* 9.自带图片/视频下载,缓存功能.
2323
* 10.支持预缓存图片及视频.
2424
* 11.支持设置完成动画.
25-
* 12.等等等...
25+
* 12.支持清除指定资源缓存.
26+
* 13.等等等...
2627

2728
### 技术交流群(群号:537476189).
2829

2930
### 更新记录:
3031

31-
* 2017.09.18 -- v3.6.0 -->1.优化图片解码方案,2.支持设置GIF动图是否循环播放
32+
* 2017.09.29 -- v3.6.1 -->1.增加清除指定图片/视频缓存接口,2.优化在iPhoneX上显示效果,3.已知问题优化与修复...
33+
* 2017.09.18 -- v3.6.0 -->1.优化图片解码方案,2.支持设置GIF动图是否循环播放...
3234
* 2017.09.13 -- v3.5.8 -->增加几种显示完成的动画...
3335
* 2017.08.20 -- v3.5.6 -->已知问题修复及内存优化...
3436
* 2017.05.26 -- v3.5.4 -->修复横屏启动造成的界面问题...
@@ -240,6 +242,7 @@ configuration.customSkipView = [self customSkipView];
240242
[button setTitle:[NSString stringWithFormat:@"自定义%lds",duration] forState:UIControlStateNormal];
241243
}
242244
```
245+
243246
### 5.预缓存接口(如果你需要提前下载并缓存广告图片或视频 请调用下面方法)
244247
```objc
245248
/**
@@ -340,10 +343,24 @@ configuration.customSkipView = [self customSkipView];
340343
```objc
341344

342345
/**
343-
* 清除XHLaunch本地缓存
346+
* 清除XHLaunch本地所有缓存
344347
*/
345348
+(void)clearDiskCache;
346349

350+
/**
351+
清除指定Url的图片本地缓存
352+
353+
@param imageUrlArray 图片Url数组
354+
*/
355+
+(void)clearDiskCacheWithImageUrlArray:(NSArray<NSURL *> *)imageUrlArray;
356+
357+
/**
358+
清除指定Url的视频本地缓存
359+
360+
@param videoUrlArray 视频url数组
361+
*/
362+
+(void)clearDiskCacheWithVideoUrlArray:(NSArray<NSURL *> *)videoUrlArray;
363+
347364
/**
348365
* 获取XHLaunch本地缓存大小(M)
349366
*/
@@ -355,6 +372,7 @@ configuration.customSkipView = [self customSkipView];
355372
+(NSString *)xhLaunchAdCachePath;
356373

357374
```
375+
358376
## 依赖
359377
#### 1.本库依赖于:FLAnimatedImage
360378

XHLaunchAd.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = "XHLaunchAd"
3-
s.version = "3.6.0"
4-
s.summary = "The screen opening advertising solutions -开屏广告解决方案,支持图片/视频、静态/动态、全屏/半屏广告,支持iPhone/iPad,自带图片下载、缓存功能,无其他三方依赖"
3+
s.version = "3.6.1"
4+
s.summary = "The screen opening advertising solutions -开屏广告、启动广告解决方案,支持图片/视频、静态/动态、全屏/半屏广告,支持iPhone/iPad,自带图片下载、缓存功能"
55
s.homepage = "https://github.com/CoderZhuXH/XHLaunchAd"
66
s.license = { :type => "MIT", :file => "LICENSE" }
77
s.authors = { "Zhu Xiaohui" => "977950862@qq.com"}

XHLaunchAd/XHLaunchAd/XHLaunchAd.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#import <Foundation/Foundation.h>
2121
#import <UIKit/UIKit.h>
2222
#import "XHLaunchAdConfiguration.h"
23-
23+
#import "XHLaunchAdConst.h"
2424

2525
NS_ASSUME_NONNULL_BEGIN
2626
@class XHLaunchAd;
@@ -159,7 +159,7 @@ NS_ASSUME_NONNULL_BEGIN
159159
*/
160160
+(void)downLoadVideoAndCacheWithURLArray:(NSArray <NSURL *> * )urlArray;
161161

162-
#pragma mark - skipAction
162+
#pragma mark - ction
163163
/**
164164
* 跳过按钮事件
165165
*/
@@ -205,6 +205,20 @@ NS_ASSUME_NONNULL_BEGIN
205205
*/
206206
+(void)clearDiskCache;
207207

208+
/**
209+
清除指定Url的图片本地缓存
210+
211+
@param imageUrlArray 图片Url数组
212+
*/
213+
+(void)clearDiskCacheWithImageUrlArray:(NSArray<NSURL *> *)imageUrlArray;
214+
215+
/**
216+
清除指定Url的视频本地缓存
217+
218+
@param videoUrlArray 视频url数组
219+
*/
220+
+(void)clearDiskCacheWithVideoUrlArray:(NSArray<NSURL *> *)videoUrlArray;
221+
208222
/**
209223
* 获取XHLaunch本地缓存大小(M)
210224
*/

XHLaunchAd/XHLaunchAd/XHLaunchAd.m

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// 代码地址:https://github.com/CoderZhuXH/XHLaunchAd
88

99
#import "XHLaunchAd.h"
10-
#import "XHLaunchAdConst.h"
1110
#import "XHLaunchAdView.h"
1211
#import "XHLaunchAdImageView+XHLaunchAdCache.h"
1312
#import "XHLaunchAdDownloader.h"
@@ -35,6 +34,7 @@ @interface XHLaunchAd()
3534
@property(nonatomic,strong)UIWindow * window;
3635
@property(nonatomic,copy)dispatch_source_t waitDataTimer;
3736
@property(nonatomic,copy)dispatch_source_t skipTimer;
37+
@property (nonatomic, assign) BOOL detailPageShowing;
3838

3939
@end
4040

@@ -83,6 +83,7 @@ +(void)skipAction
8383
{
8484
[[XHLaunchAd shareLaunchAd] adSkipButtonClick];
8585
}
86+
8687
+(BOOL)checkImageInCacheWithURL:(NSURL *)url
8788
{
8889
return [XHLaunchAdCache checkImageInCacheWithURL:url];
@@ -97,6 +98,16 @@ +(void)clearDiskCache
9798
[XHLaunchAdCache clearDiskCache];
9899
}
99100

101+
+(void)clearDiskCacheWithImageUrlArray:(NSArray<NSURL *> *)imageUrlArray
102+
{
103+
[XHLaunchAdCache clearDiskCacheWithImageUrlArray:imageUrlArray];
104+
}
105+
106+
+(void)clearDiskCacheWithVideoUrlArray:(NSArray<NSURL *> *)videoUrlArray
107+
{
108+
[XHLaunchAdCache clearDiskCacheWithVideoUrlArray:videoUrlArray];
109+
}
110+
100111
+(float)diskCacheSize
101112
{
102113
return [XHLaunchAdCache diskCacheSize];
@@ -139,6 +150,19 @@ - (instancetype)init
139150

140151
}];
141152

153+
154+
[[NSNotificationCenter defaultCenter] addObserverForName:XHLaunchAdDetailPageWillShowNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
155+
156+
_detailPageShowing = YES;
157+
158+
}];
159+
160+
[[NSNotificationCenter defaultCenter] addObserverForName:XHLaunchAdDetailPageShowFinishNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
161+
162+
_detailPageShowing = NO;
163+
164+
}];
165+
142166
}
143167
return self;
144168
}
@@ -148,14 +172,14 @@ -(void)setupLaunchAdEnterForeground
148172
switch (_launchAdType) {
149173
case XHLaunchAdTypeImage:
150174
{
151-
if(!_imageAdConfiguration.showEnterForeground) return;
175+
if(!_imageAdConfiguration.showEnterForeground || _detailPageShowing) return;
152176
[self setupLaunchAd];
153177
[self setupImageAdForConfiguration:_imageAdConfiguration];
154178
}
155179
break;
156180
case XHLaunchAdTypeVideo:
157181
{
158-
if(!_videoAdConfiguration.showEnterForeground) return;
182+
if(!_videoAdConfiguration.showEnterForeground || _detailPageShowing) return;
159183
[self setupLaunchAd];
160184
[self setupVideoAdForConfiguration:_videoAdConfiguration];
161185
}
@@ -283,7 +307,8 @@ -(void)addSkipButtonForConfiguration:(XHLaunchAdConfiguration *)configuration
283307

284308
if(_adSkipButton == nil){
285309

286-
_adSkipButton = [[XHLaunchAdButton alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width-80,20, 70, 35)];
310+
CGFloat y = XH_IPHONEX ? 44 : 20;
311+
_adSkipButton = [[XHLaunchAdButton alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width-80,y, 70, 35)];
287312
_adSkipButton.hidden = YES;
288313
[_adSkipButton addTarget:self action:@selector(adSkipButtonClick) forControlEvents:UIControlEventTouchUpInside];
289314
_adSkipButton.leftRightSpace = 5;
@@ -417,7 +442,7 @@ -(void)click
417442
XHLaunchAdConfiguration * configuration = [self commonConfiguration];
418443

419444
if ([self.delegate respondsToSelector:@selector(xhLaunchAd:clickAndOpenURLString:)] && configuration.openURLString.length) {
420-
445+
421446
[self.delegate xhLaunchAd:self clickAndOpenURLString:configuration.openURLString];
422447

423448
[self removeAndAnimateDefault];

XHLaunchAd/XHLaunchAd/XHLaunchAdCache.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,24 @@ typedef void(^VideoSaveCompletionBlock)(BOOL result , NSURL * pathURL);
136136
+ (NSString *)xhLaunchAdCachePath;
137137

138138
/**
139-
* 清除XHLaunch本地缓存
139+
* 清除XHLaunch本地所有缓存
140140
*/
141141
+(void)clearDiskCache;
142142

143+
/**
144+
清除指定Url的图片本地缓存
145+
146+
@param imageUrlArray 图片Url数组
147+
*/
148+
+(void)clearDiskCacheWithImageUrlArray:(NSArray<NSURL *> *)imageUrlArray;
149+
150+
/**
151+
清除指定Url的视频本地缓存
152+
153+
@param videoUrlArray 视频url数组
154+
*/
155+
+(void)clearDiskCacheWithVideoUrlArray:(NSArray<NSURL *> *)videoUrlArray;
156+
143157
/**
144158
* 获取XHLaunch本地缓存大小(M)
145159
*/

XHLaunchAd/XHLaunchAd/XHLaunchAdCache.m

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,39 @@ +(void)clearDiskCache
159159
});
160160

161161
}
162+
+(void)clearDiskCacheWithImageUrlArray:(NSArray<NSURL *> *)imageUrlArray
163+
{
164+
if(imageUrlArray.count==0) return;
165+
166+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
167+
168+
[imageUrlArray enumerateObjectsUsingBlock:^(NSURL * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
169+
170+
if([self checkImageInCacheWithURL:obj])
171+
{
172+
[[NSFileManager defaultManager] removeItemAtPath:[self imagePathWithURL:obj] error:nil];
173+
}
174+
}];
175+
176+
});
177+
}
178+
179+
+(void)clearDiskCacheWithVideoUrlArray:(NSArray<NSURL *> *)videoUrlArray
180+
{
181+
if(videoUrlArray.count==0) return;
182+
183+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
184+
185+
[videoUrlArray enumerateObjectsUsingBlock:^(NSURL * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
186+
187+
if([self checkVideoInCacheWithURL:obj])
188+
{
189+
[[NSFileManager defaultManager] removeItemAtPath:[self videoPathWithURL:obj] error:nil];
190+
}
191+
}];
192+
193+
});
194+
}
162195

163196
+(float)diskCacheSize
164197
{

XHLaunchAd/XHLaunchAd/XHLaunchAdConst.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,17 @@ time = nil;\
6666
view = nil;\
6767
}
6868

69+
#define XH_IPHONEX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
70+
6971
#define XHVideoName(string) [XHMd5String(string) stringByAppendingString:@".mp4"]
7072
#define XHISURLString(string) ([string hasPrefix:@"https://"] || [string hasPrefix:@"http://"]) ? YES:NO
7173
#define XHStringContainsSubString(string,subString) ([string rangeOfString:subString].location == NSNotFound) ? NO:YES
7274

73-
7475
UIKIT_EXTERN NSString *const XHCacheImageUrlStringKey;
7576
UIKIT_EXTERN NSString *const XHCacheVideoUrlStringKey;
7677

78+
UIKIT_EXTERN NSString *const XHLaunchAdDetailPageWillShowNotification;
79+
UIKIT_EXTERN NSString *const XHLaunchAdDetailPageShowFinishNotification;
7780

7881

7982

XHLaunchAd/XHLaunchAd/XHLaunchAdConst.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#import "XHLaunchAdConst.h"
1010

11-
1211
NSString *const XHCacheImageUrlStringKey = @"XHCacheImageUrlStringKey";
1312
NSString *const XHCacheVideoUrlStringKey = @"XHCacheVideoUrlStringKey";
13+
14+
NSString *const XHLaunchAdDetailPageWillShowNotification = @"XHLaunchAdDetailPageWillShowNotification";
15+
NSString *const XHLaunchAdDetailPageShowFinishNotification = @"XHLaunchAdDetailPageShowFinishNotification";

XHLaunchAd/XHLaunchAd/XHLaunchAdView.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ - (id)init
2020

2121
self.userInteractionEnabled = YES;
2222
self.frame = [UIScreen mainScreen].bounds;
23-
23+
self.layer.masksToBounds = YES;
2424
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
2525
[self addGestureRecognizer:tapGesture];
26-
2726
}
2827
return self;
2928
}

0 commit comments

Comments
 (0)