1.0.18 feat:支持新的小游戏

This commit is contained in:
eggmanQQQ
2024-10-21 18:29:30 +08:00
parent 81167d8e0f
commit b34e8ccb16
5 changed files with 135 additions and 29 deletions

View File

@@ -76,5 +76,7 @@ typedef NS_ENUM(NSInteger, ActivityType) {
///商⼾渠道BAISHUN 提供,商⼾后台可查看)
@property(nonatomic,copy) NSString *appChannel;
@end
NS_ASSUME_NONNULL_END

View File

@@ -22,4 +22,3 @@
@implementation ActivityInfoItemModel
@end

View File

@@ -53,6 +53,8 @@ NSString * const kMSGameLoaded = @"gameLoaded";
@property (nonatomic,weak) id<RoomHostDelegate> hostDelegate;
@property(nonatomic,strong) ActivityInfoModel *gameModel;
@property(nonatomic,strong) UIButton *backBtn;
@property (nonatomic, assign) BOOL isBaiShun;
@property (nonatomic, assign) BOOL isCharing;
@end
@implementation MSRoomGameWebVC
@@ -63,6 +65,7 @@ NSString * const kMSGameLoaded = @"gameLoaded";
if (self) {
self.hostDelegate = delegate;
self.gameModel = gameModel;
self.isBaiShun = [gameModel.code.uppercaseString isEqualToString:@"BAISHUN"];
}
return self;
}
@@ -77,12 +80,19 @@ NSString * const kMSGameLoaded = @"gameLoaded";
[self showLoading];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (!self.isBaiShun &&
self.isCharing) {
self.isCharing = NO;
[self updateCoin];
}
}
- (void)setupBackButton {
self.backBtn = [UIButton new];
[self.view addSubview:self.backBtn];
[self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
self.backBtn.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
[self.backBtn addTarget:self action:@selector(backBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
@@ -95,25 +105,39 @@ NSString * const kMSGameLoaded = @"gameLoaded";
[_ms_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kMSGameRecharge];
[_ms_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kMSGameLoaded];
/// LEADERCC
[_ms_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:@"closeGame"];
[_ms_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:@"pay"];
WKWebViewConfiguration *config = [WKWebViewConfiguration new];
config.allowsInlineMediaPlayback = YES;
[config setValue:@YES forKey:@"allowUniversalAccessFromFileURLs"];
//⼿,
config.mediaTypesRequiringUserActionForPlayback = NO;
config.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
config.preferences = [[WKPreferences alloc]init];
WKPreferences *preferences = [WKPreferences new];
preferences.javaScriptCanOpenWindowsAutomatically = YES;
config.preferences = preferences;
config.preferences.javaScriptEnabled = YES;
config.userContentController = _ms_userContentController;
//
int ScreenHeight = [[UIScreen mainScreen] bounds].size.height;
int ScreenWidth = [[UIScreen mainScreen] bounds].size.width;
self.webView = [[WKWebView alloc] initWithFrame:CGRectMake(0,0,
ScreenWidth, ScreenHeight) configuration:config];
CGRect frame = CGRectZero;
if (self.isBaiShun) {
frame = CGRectMake(0,0,
KScreenWidth, KScreenHeight);
} else {
if(self.gameModel.showType == ActivityShowType_Half){
frame = CGRectMake(0, KScreenHeight * 0.3,
KScreenWidth, KScreenHeight * 0.7);
} else {
frame = CGRectMake(0,0,
KScreenWidth, KScreenHeight);
}
}
self.webView = [[WKWebView alloc] initWithFrame:frame
configuration:config];
[self.webView.scrollView setBackgroundColor:[UIColor clearColor]];
[self.webView setBackgroundColor:[UIColor clearColor]];
[self.webView setUIDelegate:self];
@@ -122,19 +146,39 @@ NSString * const kMSGameLoaded = @"gameLoaded";
[self.webView setOpaque:NO];
//
if (@available(iOS 11.0, *)) {
self.webView.scrollView.contentInsetAdjustmentBehavior =
UIScrollViewContentInsetAdjustmentNever;
self.webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[self.view addSubview:self.webView];
NSString *h5Url = self.gameModel.skipContent;
NSURL *url = [NSURL URLWithString:h5Url];
NSURL *url = [self handleGameURL:h5Url];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
[self.webView loadRequest:request];
}
- (NSURL *)handleGameURL:(NSString *)url {
if (self.isBaiShun) {
return [NSURL URLWithString:url];
} else {
url = [url stringByAppendingFormat:@"&uid=%@", [AccountInfoStorage instance].getUid];
url = [url stringByAppendingFormat:@"&token=%@", self.gameModel.gameModel.code];
url = [url stringByAppendingFormat:@"&lang=%@", @"zh-CN"];
url = [url stringByAppendingFormat:@"&roomid=%ld", (long)self.hostDelegate.getRoomInfo.uid];
return [NSURL URLWithString:url];
}
return nil;
}
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
[self hideHUD];
if (self.isBaiShun) {
} else {
self.backBtn.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight*0.3);
}
#if DEBUG
NSString *fileName = @"vconsole.min.js"; //
NSString *directory = [[NSBundle mainBundle] resourcePath];
@@ -208,7 +252,6 @@ NSString * const kMSGameLoaded = @"gameLoaded";
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *err;
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONReadingMutableContainers
error:&err];
if(err)
@@ -219,25 +262,81 @@ NSString * const kMSGameLoaded = @"gameLoaded";
return dic;
}
//
- (void)userContentController:(WKUserContentController
*)userContentController
- (void)userContentController:(WKUserContentController *)userContentController
didReceiveScriptMessage:(WKScriptMessage *)message
{
// NSString* method = [NSString stringWithFormat:@"%@:", message.name];
NSDictionary *dicBody = [self dictionaryWithJsonString:message.body];
if ([message.name isEqualToString:kMSGetConfig]) {
[self getConfig:dicBody];
} else if ([message.name isEqualToString:kMSDestroy]) {
[self destroy:dicBody];
} else if ([message.name isEqualToString:kMSGameLoaded]) {
[self gameLoaded:dicBody];
} else if ([message.name isEqualToString:kMSGameRecharge]) {
[self gameRecharge:dicBody];
/// BaiShun
if (self.isBaiShun) {
NSDictionary *dicBody = [self dictionaryWithJsonString:message.body];
if ([message.name isEqualToString:kMSGetConfig]) {
[self getConfig:dicBody];
} else if ([message.name isEqualToString:kMSDestroy]) {
[self destroy:dicBody];
} else if ([message.name isEqualToString:kMSGameLoaded]) {
[self gameLoaded:dicBody];
} else if ([message.name isEqualToString:kMSGameRecharge]) {
[self gameRecharge:dicBody];
} else {
NSLog(@"未实现⽅法 : %@ --> %@", message.name, message.body);
}
} else {
NSLog(@"未实现⽅法 : %@ --> %@", message.name, message.body);
/// LeaderCC
NSString* method = [NSString stringWithFormat:@"%@:", message.name];
SEL selector = NSSelectorFromString(method);
if([self respondsToSelector:selector]){
[self performSelector:selector withObject:message.body];
}else{
NSLog(@"未實現方法 : %@ --> %@", message.name, message.body);
}
}
}
#pragma mark - LeaderCC Delegate
//
- (void)closeGame:(NSDictionary*)args {
// NSLog(@"1234");
TTAlertConfig *config = [[TTAlertConfig alloc]init];
config.message = YMLocalizedString(@"MSRoomGameWebVC0");
config.actionStyle = TTAlertActionBothStyle;
[TTPopup alertWithConfig:config showBorder:NO confirmHandler:^{
[self willMoveToParentViewController:nil]; //1
[self.view removeFromSuperview]; //2
[self removeFromParentViewController]; //3
} cancelHandler:^{
}];
}
//
- (void)pay:(NSDictionary*)args {
// TODO
TTAlertConfig *config = [[TTAlertConfig alloc]init];
config.message = YMLocalizedString(@"XPNobleCenterViewController3");
config.actionStyle = TTAlertActionBothStyle;
@kWeakify(self);
[TTPopup alertWithConfig:config showBorder:NO confirmHandler:^{
@kStrongify(self);
XPIAPRechargeViewController * webVC =[[XPIAPRechargeViewController alloc] init];
webVC.type = @"4";
[self.navigationController pushViewController:webVC animated:YES];
self.isCharing = YES;
} cancelHandler:^{
}];
}
- (void)updateCoin {
//
[self.webView evaluateJavaScript:@"updateCoin()" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
if (error) {
NSLog(@"Error calling JS function: %@", error.localizedDescription);
} else {
NSLog(@"JS function called successfully, result: %@", result);
}
}];
}
#pragma mark - BaiShun Delegate
//
- (void) getConfig:(NSDictionary*)args
{
@@ -312,10 +411,13 @@ NSString * const kMSGameLoaded = @"gameLoaded";
TTAlertConfig *config = [[TTAlertConfig alloc]init];
config.message = YMLocalizedString(@"XPNobleCenterViewController3");
config.actionStyle = TTAlertActionBothStyle;
@kWeakify(self);
[TTPopup alertWithConfig:config showBorder:NO confirmHandler:^{
@kStrongify(self);
XPIAPRechargeViewController * webVC =[[XPIAPRechargeViewController alloc] init];
webVC.type = @"4";
[self.navigationController pushViewController:webVC animated:YES];
self.isCharing = YES;
} cancelHandler:^{
}];

View File

@@ -3953,3 +3953,4 @@ ineHeadView12" = "الحمل";
"RoomMicState_1" = "لقد قمت بتشغيل الموسيقى ولكنك أوقفت الميكروفون.";
"RoomMicState_2" = "لقد أوقفت الموسيقى والميكروفون.";
"UserInfoEdit_1.0.17_0" = "Gif 头像";

View File

@@ -3748,3 +3748,5 @@
"RoomMicState_0" = "You turned on the mic and the music.";
"RoomMicState_1" = "You turned on the music but turned off the mic.";
"RoomMicState_2" = "You turned off the music and the mic.";
"UserInfoEdit_1.0.17_0" = "Gif 头像";