提交
This commit is contained in:
@@ -1,10 +1,3 @@
|
|||||||
//
|
|
||||||
// H5View.m
|
|
||||||
// TestGameWeb
|
|
||||||
//
|
|
||||||
// Created by Mac on 2024/1/30.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "H5View.h"
|
#import "H5View.h"
|
||||||
#import "CircularProgressBar.h"
|
#import "CircularProgressBar.h"
|
||||||
#import <WebKit/WebKit.h>
|
#import <WebKit/WebKit.h>
|
||||||
@@ -622,7 +615,51 @@
|
|||||||
UnitySendMessage("SdkManager", "H5AutoRefresh",[[url stringByAppendingString:@"|h6"] UTF8String]);
|
UnitySendMessage("SdkManager", "H5AutoRefresh",[[url stringByAppendingString:@"|h6"] UTF8String]);
|
||||||
|
|
||||||
}
|
}
|
||||||
//隐藏webview
|
|
||||||
|
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
|
||||||
|
|
||||||
|
NSURL *url = navigationAction.request.URL;
|
||||||
|
NSString *scheme = [url.scheme lowercaseString];
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// 【第一步】:防流氓跳转(App Store / 其他 App 唤起拦截)
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
|
// 1. 过滤 App Store 的专用协议 (itms-apps, itms-services 等)
|
||||||
|
if ([scheme hasPrefix:@"itms"]) {
|
||||||
|
decisionHandler(WKNavigationActionPolicyCancel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 过滤直连 App Store 的标准 https 链接 (apps.apple.com / itunes.apple.com)
|
||||||
|
if ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"]) {
|
||||||
|
if ([url.host containsString:@"apps.apple.com"] || [url.host containsString:@"itunes.apple.com"]) {
|
||||||
|
decisionHandler(WKNavigationActionPolicyCancel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// else {
|
||||||
|
// // 3. 拦截其他所有非 http/https 的自定义 Scheme (例如 weixin://, tbopen:// 等流氓广告唤起链接)
|
||||||
|
// // 除非网页中需要支持特定功能(如微信支付),否则一律拦截以防止乱跳
|
||||||
|
// decisionHandler(WKNavigationActionPolicyCancel);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// 【第二步】:处理 target="_blank" (新标签页/新窗口打开链接的问题)
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
|
// 如果是用户点击链接,且该链接不是在当前主窗口打开
|
||||||
|
if (navigationAction.navigationType == WKNavigationTypeLinkActivated && !navigationAction.targetFrame.isMainFrame) {
|
||||||
|
// 拒绝默认的新窗口跳转
|
||||||
|
decisionHandler(WKNavigationActionPolicyCancel);
|
||||||
|
// 强行在当前窗口中重新加载该链接
|
||||||
|
[webView loadRequest:navigationAction.request];
|
||||||
|
} else {
|
||||||
|
// 其余情况(正常的主页面跳转、JS 自动加载等),一律放行
|
||||||
|
decisionHandler(WKNavigationActionPolicyAllow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//设置飞行进度条进度
|
//设置飞行进度条进度
|
||||||
-(void)setIconProgress:(float)value{
|
-(void)setIconProgress:(float)value{
|
||||||
@@ -1117,6 +1154,12 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(BOOL)GetThrough{
|
||||||
|
|
||||||
|
return dark_though;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
#import <objc/runtime.h>
|
#import <objc/runtime.h>
|
||||||
#import <QuartzCore/QuartzCore.h>
|
#import <QuartzCore/QuartzCore.h>
|
||||||
|
#include "H5View.h"
|
||||||
extern UIView *UnityGetGLView(void);
|
extern UIView *UnityGetGLView(void);
|
||||||
|
|
||||||
@interface UIApplication (UnityTouchHook)
|
@interface UIApplication (UnityTouchHook)
|
||||||
@@ -43,9 +43,13 @@ static Ivar g_ivarPrevLocation = NULL;
|
|||||||
|
|
||||||
- (void)ut_sendEvent:(UIEvent *)event
|
- (void)ut_sendEvent:(UIEvent *)event
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
// 1. 让系统和 WebView 先走正常响应
|
// 1. 让系统和 WebView 先走正常响应
|
||||||
[self ut_sendEvent:event];
|
[self ut_sendEvent:event];
|
||||||
|
if (![[H5View shared] GetThrough]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (event.type != UIEventTypeTouches)
|
if (event.type != UIEventTypeTouches)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user