提交web的修改

This commit is contained in:
linyudan
2023-11-29 15:18:56 -08:00
parent 0e2006b347
commit 0fe2be212f
3 changed files with 196 additions and 40 deletions

View File

@@ -2705,7 +2705,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.4.1;
MARKETING_VERSION = 1.0.0;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "linyudan.yinmeng-ios";
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -2750,7 +2750,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.4.1;
MARKETING_VERSION = 1.0.0;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "linyudan.yinmeng-ios";
PRODUCT_NAME = "$(TARGET_NAME)";

View File

@@ -25,7 +25,7 @@
}
+ (NSString *)appName {
return @"yinmeng";
return @"mew";
}
+ (NSString *)appBuild{
@@ -109,12 +109,12 @@ static NSString *_from = nil;
&& ![from isEqualToString:@""]) {
_from = from;
} else {
if (isEnterprise) {
_from = @"yinmeng_Enterprise"; //
}else {
_from = @"yinmeng_appstore"; // App Store
}
_from = @"yinmeng_Enterprise"; //
// if (isEnterprise) {
// _from = @"yinmeng_Enterprise"; //
// }else {
// _from = @"mew_appstore"; // App Store
// }
_from = @"mew_appstore"; //
}
}

View File

@@ -6,22 +6,23 @@
//
#import "YMWebViewController.h"
#import "MewLoginViewController.h"
#import "BaseNavigationController.h"
/// Tool
#import "ApiHost.h"
#import "Api+Mine.h"
#import "YYUtility.h"
#import "AccountInfoStorage.h"
#import "ThemeColor.h"
#import "YMMacro.h"
#import "NewEncryptTool.h"
#import "HttpRequestHelper.h"
#import "AccountModel.h"
#import "YMHUDTool.h"
#import "ClientConfig.h"
/// Third
#import <Masonry/Masonry.h>
//#ifdef DEBUG
//static const NSString *CompanyFirstDomainByWeChatRegister = @"api.uat.lecheng163.com";
//#else
//static const NSString *CompanyFirstDomainByWeChatRegister = @"api.lecheng163.com";
//#endif
#import <MJExtension/MJExtension.h>
@interface WeakWebViewScriptMessageDelegate : NSObject<WKScriptMessageHandler>
@@ -54,40 +55,41 @@
@end
NSString * const kJSGetUid = @"getUid";
NSString * const kJSGetDeviceId = @"getDeviceId";
NSString * const kJSGetTicket = @"getTicket";
NSString * const kJSGetDeviceInfo = @"getDeviceInfo";
NSString * const kInitShowNav = @"initShowNav";
NSString * const kCloseWebView = @"closeWebView";
NSString * const kCancelAccount = @"cancelAccount";
@interface YMWebViewController ()<WKNavigationDelegate, WKScriptMessageHandler>
@property (strong, nonatomic) WKWebView *webview;
@property (nonatomic, strong) WKUserContentController *userContentController;
///
@property (nonatomic,assign) BOOL isHiddenNav;
@end
@implementation YMWebViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.isHiddenNav = NO;
[self initView];
NSString *urlString = [NSString stringWithFormat:@"%@/%@", [NewEncryptTool MEW_aesDecrypt: API_HOST_H5_URL], self.url];
[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];
}
- (void)backButtonClick {
BOOL canGoBack = YES;
if (self.webview.backForwardList.backList.count <= 1) {
canGoBack = NO;
}
if ([self.webview canGoBack]) {
[self.webview goBack];
} else {
[self.navigationController popViewControllerAnimated:YES];
// [self.userContentController removeAllUserScripts];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.navigationController setNavigationBarHidden:self.isHiddenNav animated:animated];
}
#pragma mark - InitView
- (void)initView {
if (@available(iOS 11.0, *)) {
self.webview.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
@@ -99,19 +101,115 @@ NSString * const kJSGetUid = @"getUid";
make.left.right.top.bottom.mas_equalTo(self.view);
}];
}
#pragma mark - Set
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
[self.webview evaluateJavaScript:@"document.location.href" completionHandler:^(id _Nullable response, NSError * _Nullable error) {
NSLog(@"%@", response);
NSString *currentUrl = [NSString stringWithFormat:@"%@", response];
///host,便h5
#ifdef DEBUG
if (currentUrl != nil) {
#else
if (currentUrl != nil) {
#endif
if ([message.name isEqualToString:kJSGetUid]) {
NSString *uid = [[AccountInfoStorage instance] getUid];
NSString *js = [NSString stringWithFormat:@"getMessage(\"uid\",%@)", uid];
[self.webview evaluateJavaScript:js completionHandler:^(id _Nullable other, NSError * _Nullable error) {
NSLog(@"%@",error);
}];
} else if ([message.name isEqualToString:kJSGetTicket]) {
NSString *ticket = [[AccountInfoStorage instance] getTicket];
NSString *js = [NSString stringWithFormat:@"getMessage(\"ticket\",\"%@\")",ticket];
[self.webview evaluateJavaScript:js completionHandler:^(id _Nullable other, NSError * _Nullable error) {
NSLog(@"%@",error);
}];
} else if ([message.name isEqualToString:kJSGetDeviceId]) {
NSString *js = [NSString stringWithFormat:@"getMessage(\"deviceId\",\"%@\")",[YYUtility deviceUniqueIdentification]];
[self.webview evaluateJavaScript:js completionHandler:^(id _Nullable other, NSError * _Nullable error) {
NSLog(@"%@",error);
}];
} else if ([message.name isEqualToString:kJSGetDeviceInfo]) {
NSDictionary *basicParmars = [HttpRequestHelper configBaseParmars:[[NSDictionary alloc] init]];
NSString *json = [basicParmars mj_JSONString];
NSString *js = [NSString stringWithFormat:@"getMessage(\"deviceInfo\",%@)", json];
[self.webview evaluateJavaScript:js completionHandler:^(id _Nullable ohter, NSError * _Nullable error) {
NSLog(@"%@", error);
}];
} else if([message.name isEqualToString:kInitShowNav]) {
if (((NSNumber *)message.body).intValue == 0) {
self.isHiddenNav = YES;
if (self.navigationController) {
[self.navigationController setNavigationBarHidden:YES];
}
}
} else if([message.name isEqualToString:kCloseWebView]) {
if (self.navigationController) {
[self.navigationController popViewControllerAnimated:YES];
}
} else if ([message.name isEqualToString:kCancelAccount]) {
[YMHUDTool showLoadingWithMessage:@"正在注销中,请稍等"];
AccountModel *model = [[AccountInfoStorage instance] accountModel];
[Api logoutCurrentAccount:^(BaseModel * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
[YMHUDTool showSuccessWithMessage:@"注销成功"];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.navigationController popToRootViewControllerAnimated:NO];
[[AccountInfoStorage instance] saveAccountInfo:nil];
[[AccountInfoStorage instance] saveTicket:nil];
///
[[ClientConfig shareConfig] resetHeartBratTimer];
MewLoginViewController *loginVC = [[MewLoginViewController alloc] init];
BaseNavigationController * nav = [[BaseNavigationController alloc] initWithRootViewController:loginVC];
nav.modalPresentationStyle = UIModalPresentationFullScreen;
[self.navigationController presentViewController:nav animated:YES completion:nil];
});
} access_token:model.access_token];
}
}
}];
}
- (void)setUrl:(NSString *)urlString{
_url = urlString;
if (_url == nil) {
return;
}
if (![_url hasPrefix:@"http"] && ![_url hasPrefix:@"https"]){
_url = [NSString stringWithFormat:@"%@/%@", [NewEncryptTool MEW_aesDecrypt:API_HOST_H5_URL], _url];
}
if (![_url containsString:@"alipayh5"]) {
if (![_url containsString:@"?"]) {
_url = [NSString stringWithFormat:@"%@?platform=%@", _url, [YYUtility appName]];
} else {
_url = [NSString stringWithFormat:@"%@&platform=%@", _url, [YYUtility appName]];
}
}
// urlString
NSString *noSpaceTextUrl = [_url stringByReplacingOccurrencesOfString:@" " withString:@""];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:noSpaceTextUrl]];
[self.webview loadRequest:request];
}
- (void)backButtonClick {
BOOL canGoBack = YES;
if (self.webview.backForwardList.backList.count <= 1) {
canGoBack = NO;
}
#pragma mark - Get
if ([self.webview canGoBack]) {
[self.webview goBack];
} else {
[self.navigationController popViewControllerAnimated:YES];
[self.userContentController removeAllUserScripts];
}
}
- (WKWebView *)webview {
if (_webview == nil) {
@@ -122,18 +220,76 @@ NSString * const kJSGetUid = @"getUid";
} else {
// Fallback on earlier versions
}
configuration.allowsInlineMediaPlayback = YES;
_webview = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
NSString *uid = [[AccountInfoStorage instance] getUid];
NSString *realCookie = [NSString stringWithFormat:@"%@=%@",@"uid",uid];
WKUserScript *cookieScript = [[WKUserScript alloc] initWithSource: [NSString stringWithFormat:@"document.cookie = '%@';", realCookie] injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:NO];
[self.userContentController addUserScript:cookieScript];
///
NSString *scaleJs = @"$('meta[name=description]').remove(); $('head').append( '<meta name=\"viewport\" content=\"width=device-width, initial-scale=1,user-scalable=no\">' );";
WKUserScript *scaleScript = [[WKUserScript alloc] initWithSource:scaleJs injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:NO];
[self.userContentController addUserScript:scaleScript];
//WKUserScriptWKWebViewConfiguration
configuration.preferences.javaScriptEnabled = YES;
configuration.preferences.javaScriptCanOpenWindowsAutomatically = YES;
configuration.preferences.minimumFontSize = 10;
configuration.selectionGranularity = WKSelectionGranularityCharacter;
configuration.userContentController = self.userContentController;
CGSize size = [UIScreen mainScreen].bounds.size;
_webview = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, size.width,size.height) configuration:configuration];
_webview.navigationDelegate = self;
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(backButtonClick)];
[_webview addGestureRecognizer:swipeGesture];
[_webview.scrollView setShowsVerticalScrollIndicator:NO];
[_webview.scrollView setShowsHorizontalScrollIndicator:NO];
//set useragent
__weak typeof(self) weakSelf = self;
[_webview evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id result, NSError *error) {
NSString *userAgent = result;
if (![userAgent containsString:@"tutuAppIos erbanAppIos"]){
NSString *newUserAgent = [userAgent stringByAppendingString:@" tutuAppIos erbanAppIos"];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:newUserAgent, @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
[[NSUserDefaults standardUserDefaults] synchronize];
[weakSelf.webview setCustomUserAgent:newUserAgent];
}
}];
_webview.scrollView.bounces = NO;
}
return _webview;
}
- (WKUserContentController *)userContentController{
if (!_userContentController) {
//WKScriptMessageHandler
WeakWebViewScriptMessageDelegate *weakScriptMessageDelegate = [[WeakWebViewScriptMessageDelegate alloc] initWithDelegate:self];
_userContentController = [[WKUserContentController alloc] init];
// uid
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJSGetUid];
// id
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJSGetDeviceId];
// Ticket
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJSGetTicket];
// info
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJSGetDeviceInfo];
//
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kInitShowNav];
//
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kCloseWebView];
//
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kCancelAccount];
}
return _userContentController;
}
@end