fix:修正所有礼物缓存问题

This commit is contained in:
eggmanQQQ
2024-08-14 16:32:40 +08:00
parent 39f928be02
commit d555f5815c
6 changed files with 40 additions and 31 deletions

View File

@@ -46,8 +46,10 @@
- (void)preLoadGifts {
[Api requestAllTagsAndNormalGifts:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200 && data.data) {
[[XPGiftStorage shareStorage] cacheTagsWith:data.data
inRoom:[[XPGiftStorage shareStorage] defaultKey]];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[[XPGiftStorage shareStorage] cacheTagsWith:data.data
inRoom:[[XPGiftStorage shareStorage] defaultKey]];
});
}
} roomUid:@""];
}

View File

@@ -179,23 +179,15 @@
///
/// @param roomUid uid
- (void)getNormalGiftList:(NSString *)roomUid {
// return;
///
// CGFloat delayDuration = 0.0;
// NSArray *giftCacheArray = [[XPGiftStorage shareStorage] getGiftPanelTagsDatasource:roomUid];
// if (giftCacheArray.count > 0) {
// delayDuration = 0.25;
// }
// load
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayDuration * NSEC_PER_SEC)), dispatch_get_global_queue(0, 0), ^{
[Api requestAllTagsAndNormalGifts:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200 && data.data) {
// [[XPGiftStorage shareStorage] cacheWith:data.data inRoom:roomUid];
[[XPGiftStorage shareStorage] cacheTagsWith:data.data inRoom:roomUid];
}
} roomUid:roomUid];
// });
[[XPGiftStorage shareStorage] updateRoomUID:roomUid];
[Api requestAllTagsAndNormalGifts:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200 && data.data) {
[[XPGiftStorage shareStorage] cacheTagsWith:data.data inRoom:roomUid];
}
} roomUid:roomUid];
}
///

View File

@@ -31,7 +31,9 @@ NS_ASSUME_NONNULL_BEGIN
/// @param giftId 礼物的id
- (GiftInfoModel *)findGiftInfo:(NSString *)giftId;
//- (NSArray *)cacheWith:(NSDictionary *)response inRoom:(NSString *)roomUid;
// 进房时需要主动更新 roomID礼物 model 会优先从对应的
- (void)updateRoomUID:(NSString *)roomUID;
- (NSArray *)cacheTagsWith:(NSDictionary *)response inRoom:(NSString *)roomUid;
@end

View File

@@ -132,10 +132,14 @@
return _roomGiftPanelTagsCache;
}
- (void)updateRoomUID:(NSString *)roomUID
{
self.currentRoomUid = roomUID;
}
/// API tab/tab
- (NSArray *)cacheTagsWith:(NSDictionary *)response inRoom:(NSString *)roomUid {
NSArray *tabModels = [GiftPanelTabModel modelsWithArray:response[@"tabList"]];
[self saveGiftPanelTagsDatasource:tabModels roomUid:roomUid];
NSDictionary *contents = response;
if ([[response allKeys] containsObject:@"giftTabMap"]) {
@@ -144,21 +148,29 @@
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"seq" ascending:YES];
NSMutableArray <GiftPanelTabModel *>*mutableTabs = [tabModels sortedArrayUsingDescriptors:@[sortDescriptor]].mutableCopy;
NSMutableArray *totalInfo = [NSMutableArray array];
// Tab
for (GiftPanelTabModel *model in mutableTabs) {
NSString *key = model.key;
NSArray *giftsArray = [contents objectForKey:key];
if (giftsArray.count > 0) {
NSArray *giftModels = [GiftInfoModel modelsWithArray:giftsArray];
model.gifts = giftModels;
[totalInfo addObjectsFromArray:giftModels];
}
}
//
NSMutableArray *totalInfo = [NSMutableArray array];
for (NSString *key in contents) {
NSArray *giftModels = [GiftInfoModel modelsWithArray:[contents objectForKey:key]];
[totalInfo addObjectsFromArray:giftModels];
}
[self saveGiftDatasource:totalInfo roomUid:roomUid];
[self saveGiftPanelTagsDatasource:mutableTabs roomUid:roomUid];
self.currentRoomUid = roomUid;
return mutableTabs;
}

View File

@@ -40,7 +40,7 @@ NS_ASSUME_NONNULL_BEGIN
///关闭webView 目前适用于半屏的情况下
@property (nonatomic,copy) void (^CloseWebViewBlock)(BOOL result);
- (instancetype)initWithCustomizeNav:(BOOL)isCustom;
- (instancetype)initWithGame;
//- (instancetype)initWithGame;
@end
NS_ASSUME_NONNULL_END

View File

@@ -72,7 +72,7 @@ typedef NS_ENUM(NSUInteger, RightNavigationPushType){
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
if ([self.scriptDelegate respondsToSelector:@selector(userContentController:didReceiveScriptMessage:)]) {
[self.scriptDelegate userContentController:userContentController didReceiveScriptMessage:message];
[self.scriptDelegate userContentController:userContentController didReceiveScriptMessage:message];
}
}
@@ -300,7 +300,7 @@ NSString * const kJSOpenPaymentCallback = @"openPaymentCallback";
}
- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler{
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
dispatch_async(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSURLCredential *card = [[NSURLCredential alloc]initWithTrust:challenge.protectionSpace.serverTrust];
completionHandler(NSURLSessionAuthChallengeUseCredential,card);
});
@@ -314,7 +314,6 @@ NSString * const kJSOpenPaymentCallback = @"openPaymentCallback";
NSLog(@"-- -- - -- - -%@: %@", message.name, message.body);
NSString *currentUrl = [NSString stringWithFormat:@"%@", response];
///host,便h5
BOOL condition = currentUrl != nil && [currentUrl containsString:API_HOST_URL];
#ifdef DEBUG
condition = currentUrl != nil;
@@ -1051,10 +1050,12 @@ NSString * const kJSOpenPaymentCallback = @"openPaymentCallback";
}
return _navView;
}
- (PIWebViewSavePhotoView *)saveView{
if(!_saveView){
_saveView = [[PIWebViewSavePhotoView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
}
return _saveView;
- (PIWebViewSavePhotoView *)saveView{
if(!_saveView){
_saveView = [[PIWebViewSavePhotoView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
}
return _saveView;
}
@end