Skip to content

Commit 0acfbd2

Browse files
committed
add IDFA for request and check weakself
1 parent 24b1d31 commit 0acfbd2

File tree

8 files changed

+72
-32
lines changed

8 files changed

+72
-32
lines changed

VideoPlsInterfaceControllerSDK/VideoPlsInterfaceControllerSDK/VideoPlsInterfaceControllerSDK/VPInterfaceController.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,13 +570,17 @@ - (void)registerLuaViewRoutes {
570570
__weak typeof(self) weakSelf = self;
571571
[[VPUPRoutes routesForScheme:VPUPRoutesSDKLuaView] addRoute:@"/defaultLuaView" handler:^BOOL(NSDictionary<NSString *,id> * _Nonnull parameters) {
572572

573+
if (weakSelf) {
574+
return NO;
575+
}
576+
__strong typeof(self) strongSelf = weakSelf;
573577
//判定osView是否存在,若不存在,先创建
574-
if (!weakSelf.osView) {
575-
[weakSelf initOSViewWithFrame:weakSelf.view.bounds];
578+
if (!strongSelf.osView) {
579+
[strongSelf initOSViewWithFrame:strongSelf.view.bounds];
576580
//TODO MQTT,如果_liveView不存在情况怎么处理
577581

578-
if(!weakSelf.canSet) {
579-
[weakSelf.osView startLoading];
582+
if(!strongSelf.canSet) {
583+
[strongSelf.osView startLoading];
580584
}
581585
}
582586

@@ -590,7 +594,7 @@ - (void)registerLuaViewRoutes {
590594
if (!luaFile) {
591595
luaFile = [data objectForKey:@"template"];
592596
}
593-
[weakSelf.osView loadLua:luaFile data:parameters];
597+
[strongSelf.osView loadLua:luaFile data:parameters];
594598
return YES;
595599
}];
596600
}

VideoPlsLuaViewManagerSDK/VideoPlsLuaViewManagerSDK/VideoPlsLuaViewManagerSDK/VPLua/LuaView/VPLuaNativeScanner.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ - (void)showPhotoPickerController:(NSString *)requestMethod {
3636
__weak typeof(self) weakSelf = self;
3737

3838
imagePicker.imagePickerControllerDidCancelHandle = ^(void) {
39+
if (!weakSelf) {
40+
return;
41+
}
3942
lua_State* l = self.luaNode.lvCore.l;
4043
if( l ){
4144
lua_checkstack32(l);
@@ -45,6 +48,9 @@ - (void)showPhotoPickerController:(NSString *)requestMethod {
4548
};
4649

4750
imagePicker.didFinishPickingPhotosWithFilePathHandle = ^(NSString *filePath) {
51+
if (!weakSelf) {
52+
return;
53+
}
4854
lua_State* l = self.luaNode.lvCore.l;
4955
if( l ){
5056
lua_checkstack32(l);

VideoPlsLuaViewManagerSDK/VideoPlsLuaViewManagerSDK/VideoPlsLuaViewManagerSDK/VPLua/Manager/VPLuaCommonInfo.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ + (NSMutableDictionary *)commonParam {
2626
[_commonParam setObject:[VPUPGeneralInfo platformSDKVersion] forKey:@"SDK_VERSION"];
2727
[_commonParam setObject:[VPUPGeneralInfo appDeviceSystemVersion] forKey:@"OS_VERSION"];
2828
[_commonParam setObject:[VPUPGeneralInfo userIdentity] forKey:@"UD_ID"];
29+
[_commonParam setObject:[VPUPGeneralInfo IDFA] forKey:@"IDFA"];
2930
[_commonParam setObject:[VPUPGeneralInfo appDeviceLanguage] forKey:@"LANGUAGE"];
3031
[_commonParam setObject:[VPUPGeneralInfo iPhoneDeviceType] forKey:@"PHONE_MODEL"];
3132
[_commonParam setObject:[VPUPDeviceUtil phoneCarrier] forKey:@"PHONE_PROVIDER"];

VideoPlsLuaViewManagerSDK/VideoPlsLuaViewManagerSDK/VideoPlsLuaViewManagerSDK/VPLua/Manager/VPLuaScriptManager.m

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#import "VPLuaScriptManager.h"
1010
#import "VPUPResumeDownloader.h"
11-
#import "VPUPHTTPGeneralAPI.h"
11+
#import "VPUPHTTPBusinessAPI.h"
1212
#import "VPUPHTTPAPIManager.h"
1313
#import "VPUPJsonUtil.h"
1414
#import <VPLuaViewSDK/LVZipArchive.h>
@@ -63,47 +63,48 @@ - (VPUPPrefetchManager *)prefetchManager {
6363

6464
- (void)getLuaVersionInfoWithVersionUrl:(NSString *)url {
6565
__weak typeof(self) weakSelf = self;
66-
VPUPHTTPGeneralAPI *api = [[VPUPHTTPGeneralAPI alloc] init];
67-
if ([VPLuaSDK sharedSDK].appKey && [VPLuaSDK sharedSDK].appKey.length > 0) {
68-
NSMutableDictionary *headers = [NSMutableDictionary dictionaryWithCapacity:0];
69-
[headers addEntriesFromDictionary:api.apiRequestHTTPHeaderField];
70-
[headers setObject:[VPLuaSDK sharedSDK].appKey forKey:@"appKey"];
71-
api.apiRequestHTTPHeaderField = headers;
72-
}
66+
VPUPHTTPBusinessAPI *api = [[VPUPHTTPBusinessAPI alloc] init];
7367
api.baseUrl = url;
7468
api.apiRequestMethodType = VPUPRequestMethodTypePOST;
7569
NSString *commonParamString = VPUP_DictionaryToJson(@{@"commonParam":[VPLuaCommonInfo commonParam]});
7670
api.requestParameters = @{@"data":[VPUPAESUtil aesEncryptString:commonParamString key:[VPLuaSDK sharedSDK].appSecret initVector:[VPLuaSDK sharedSDK].appSecret]};
7771
api.apiCompletionHandler = ^(id _Nonnull responseObject, NSError * _Nullable error, NSURLResponse * _Nullable response) {
7872

73+
if (!weakSelf) {
74+
return;
75+
}
76+
77+
__strong typeof(self) strongSelf = weakSelf;
78+
7979
if (error || !responseObject || ![responseObject objectForKey:@"encryptData"]) {
80-
[weakSelf error:error type:VPLuaScriptManagerErrorTypeGetVersion];
80+
[strongSelf error:error type:VPLuaScriptManagerErrorTypeGetVersion];
8181
return;
8282
}
83+
8384
NSString *dataString = [VPUPAESUtil aesDecryptString:[responseObject objectForKey:@"encryptData"] key:[VPLuaSDK sharedSDK].appSecret initVector:[VPLuaSDK sharedSDK].appSecret];
84-
weakSelf.versionData = dataString;
85+
strongSelf.versionData = dataString;
8586
NSDictionary *data = VPUP_JsonToDictionary(dataString);
8687

8788
NSString *version = [data objectForKey:@"version"];
88-
NSString *versionFileString = [NSString stringWithContentsOfURL:[NSURL fileURLWithPath:weakSelf.versionFilePath] encoding:NSUTF8StringEncoding error:nil];
89+
NSString *versionFileString = [NSString stringWithContentsOfURL:[NSURL fileURLWithPath:strongSelf.versionFilePath] encoding:NSUTF8StringEncoding error:nil];
8990
NSDictionary *versionFile = VPUP_JsonToDictionary(versionFileString);
9091
NSString *localVersion = [versionFile objectForKey:@"version"];
9192

9293
if (!localVersion || ![localVersion isEqualToString:version]) {
9394

9495
NSString *url = [data objectForKey:@"downloadUrl"];
9596
if (!url || [url isEqual:[NSNull null]]) {
96-
[weakSelf error:error type:VPLuaScriptManagerErrorTypeDownloadFile];
97+
[strongSelf error:error type:VPLuaScriptManagerErrorTypeDownloadFile];
9798
return;
9899
}
99100

100101
//下载并删除之前下载的所有文件
101102
//[weakSelf removeAllFileAtLuaPath];
102-
[weakSelf downloadWithFileUrl:data];
103+
[strongSelf downloadWithFileUrl:data];
103104
return;
104105
}
105106
// 无需下载,本地已经是最新版本
106-
[weakSelf downloadSuccess:YES];
107+
[strongSelf downloadSuccess:YES];
107108
};
108109
[_apiManager sendAPIRequest:api];
109110
}
@@ -195,7 +196,7 @@ - (void)downloadFilesList:(NSArray *)filesList {
195196
}
196197
else {
197198
count = 0;
198-
[self checkDownLoadFiles:filesList];
199+
[weakSelf checkDownLoadFiles:filesList];
199200
}
200201
}];
201202
count ++;

VideoPlsUtilsPlatformSDK/VideoPlsUtilsPlatformSDK/VideoPlsUtilsPlatformSDK/Common/DownLoad/VPUPResumeDownloader.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ - (void)cancelBySaveData:(BOOL)isSaveData
404404
self.isSaveStepCancel = isSaveData;
405405
__weak __typeof(self) weakSelf = self;
406406
[self.downloadTask cancelByProducingResumeData:^(NSData * _Nullable resumeData) {
407+
if (!weakSelf) {
408+
return;
409+
}
407410
__strong __typeof(weakSelf) strongSelf = weakSelf;
408411
NSURL *localUrl = [strongSelf incompleteDownloadTempPathForDownloadPath:strongSelf.downloadUrl];
409412
[resumeData writeToURL:localUrl atomically:YES];

VideoPlsUtilsPlatformSDK/VideoPlsUtilsPlatformSDK/VideoPlsUtilsPlatformSDK/Common/HTTP/VPUPHTTPBusinessAPI.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ - (nullable NSDictionary *)apiRequestHTTPHeaderField {
2727
NSString *udid = [[VPUPGeneralInfo IDFA] copy];
2828
if(VPUP_IsStringTrimExist(udid)) {
2929
[headerField setObject:udid
30-
forKey:@"udid"];
30+
forKey:@"IDFA"];
3131
}
3232

3333
NSString *userIdentity = [[VPUPGeneralInfo userIdentity] copy];

VideoPlsUtilsPlatformSDK/VideoPlsUtilsPlatformSDK/VideoPlsUtilsPlatformSDK/Common/Player/VPUPPlayer.m

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,13 @@ - (void)play {
7575
@try {
7676
__weak typeof(self) weakSelf = self;
7777
[_player seekToTime:self.currentTime toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:^(BOOL finished) {
78+
if (!weakSelf) {
79+
return;
80+
}
81+
__strong __typeof(weakSelf) strongSelf = weakSelf;
7882
if (finished) {
79-
[weakSelf.player play];
80-
self.status = VPUPPlayerStatusPlaying;
83+
[strongSelf.player play];
84+
strongSelf.status = VPUPPlayerStatusPlaying;
8185
}
8286
}];
8387
} @catch (NSException *exception) {
@@ -179,21 +183,27 @@ - (void)addPlayerObserver {
179183
[_player.currentItem addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil];
180184
_timeObserver = [self.player addPeriodicTimeObserverForInterval:CMTimeMake(1, 3) queue:NULL usingBlock:^(CMTime time) {
181185

182-
CMTime current = weakSelf.player.currentItem.currentTime;
183-
CMTime duration = weakSelf.player.currentItem.duration;
186+
if (!weakSelf) {
187+
return;
188+
}
189+
190+
__strong typeof(self) strongSelf = weakSelf;
191+
192+
CMTime current = strongSelf.player.currentItem.currentTime;
193+
CMTime duration = strongSelf.player.currentItem.duration;
184194

185-
if ([weakSelf.playerDelegate respondsToSelector:@selector(player:playedTime:totalTime:)]) {
186-
[weakSelf.playerDelegate player:weakSelf playedTime:((double)current.value/current.timescale) totalTime:((double)duration.value/duration.timescale)];
195+
if ([strongSelf.playerDelegate respondsToSelector:@selector(player:playedTime:totalTime:)]) {
196+
[strongSelf.playerDelegate player:strongSelf playedTime:((double)current.value/current.timescale) totalTime:((double)duration.value/duration.timescale)];
187197
}
188198

189199
double margin = ((double)duration.value/duration.timescale) - ((double)current.value/current.timescale);
190200

191-
if (weakSelf.video.ex > 0 && weakSelf.video.ex < ((double)current.value/current.timescale)) {
192-
[weakSelf playbackFinished];
201+
if (strongSelf.video.ex > 0 && strongSelf.video.ex < ((double)current.value/current.timescale)) {
202+
[strongSelf playbackFinished];
193203
}
194204

195205
if (margin <= 0.5 && margin > 0) {
196-
[weakSelf playbackFinished];
206+
[strongSelf playbackFinished];
197207
}
198208

199209

VideoPlsUtilsPlatformSDK/VideoPlsUtilsPlatformSDK/VideoPlsUtilsPlatformSDK/Subspec/MQTT/VPUPMQTTMosquittoManager.m

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ - (void)addTopic:(NSString *)topic observer:(id<VPUPMQTTObserverProtocol>)observ
124124
- (void)addTopic:(NSString *)topic qos:(VPUPMQTTQoSLevel)qos observer:(id<VPUPMQTTObserverProtocol>)observer {
125125
__weak typeof(self) weakSelf = self;
126126
dispatch_async(mqtt_manager_queue(), ^{
127+
if (!weakSelf) {
128+
return;
129+
}
127130
__strong typeof(weakSelf) strongSelf = weakSelf;
128131
if (!strongSelf || !observer) {
129132
return;
@@ -170,6 +173,9 @@ - (void)addTopics:(NSArray<NSString *> *)topic observer:(id<VPUPMQTTObserverProt
170173
- (void)attachWithObserver:(id<VPUPMQTTObserverProtocol>)observer {
171174
__weak typeof(self) weakSelf = self;
172175
dispatch_async(mqtt_manager_queue(), ^{
176+
if (!weakSelf) {
177+
return;
178+
}
173179
__strong typeof(weakSelf) strongSelf = weakSelf;
174180
if(!strongSelf.canConnect) {
175181
return;
@@ -192,10 +198,10 @@ - (void)attachWithObserver:(id<VPUPMQTTObserverProtocol>)observer {
192198
- (void)detachWithObserver:(id<VPUPMQTTObserverProtocol>)observer {
193199
__weak typeof(self) weakSelf = self;
194200
dispatch_async(mqtt_manager_queue(), ^{
195-
__strong typeof(weakSelf) strongSelf = weakSelf;
196-
if (!strongSelf) {
201+
if (!weakSelf) {
197202
return;
198203
}
204+
__strong typeof(weakSelf) strongSelf = weakSelf;
199205

200206
[strongSelf.topicObservers.allKeys enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
201207
NSMutableArray *observers = [strongSelf.topicObservers objectForKey:obj];
@@ -287,6 +293,9 @@ - (void)connectWithConfig:(VPUPMQTTConfig *)config {
287293
__weak typeof(self) weakSelf = self;
288294
dispatch_barrier_async(self.mqttQueue, ^{
289295

296+
if (!weakSelf) {
297+
return;
298+
}
290299
__strong typeof(weakSelf) strongSelf = weakSelf;
291300

292301
VPUPMQTTConfig *useConfig = config;
@@ -353,6 +362,9 @@ - (void)subscribeTopic:(NSString *)topic qos:(VPUPMQTTQoSLevel)qos {
353362
__weak typeof(self) weakSelf = self;
354363
[self.session subscribeToTopic:topic atLevel:MQTTQosLevelAtMostOnce subscribeHandler:^(NSError *error, NSArray<NSNumber *> *gQoss) {
355364
dispatch_async(mqtt_manager_queue(), ^{
365+
if (!weakSelf) {
366+
return;
367+
}
356368
__strong typeof(weakSelf) strongSelf = weakSelf;
357369
NSArray *observers = [strongSelf.topicObservers objectForKey:topic];
358370
if([observers count] == 0) {
@@ -425,6 +437,9 @@ - (void)onMessage:(NSData *)message topic:(NSString *)topic {
425437

426438
__weak typeof(self) weakSelf = self;
427439
dispatch_async(mqtt_manager_queue(), ^{
440+
if (!weakSelf) {
441+
return;
442+
}
428443
__strong typeof(weakSelf) strongSelf = weakSelf;
429444
NSArray *observers = [strongSelf.topicObservers objectForKey:topic];
430445

0 commit comments

Comments
 (0)