fix:1、添加跳链接的webview的插件。2、修复bug

This commit is contained in:
2026-07-14 16:12:11 +08:00
parent 110660f299
commit bb84cea894
79 changed files with 4455 additions and 512 deletions
File diff suppressed because it is too large Load Diff
+58
View File
@@ -0,0 +1,58 @@
fileFormatVersion: 2
guid: 60e7bf38137eb4950b2f02b7d57c1ad3
folderAsset: yes
PluginImporter:
serializedVersion: 1
iconMap: {}
executionOrder: {}
isPreloaded: 0
platformData:
Android:
enabled: 0
settings:
CPU: AnyCPU
Any:
enabled: 0
settings: {}
Editor:
enabled: 1
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: OSX
Linux:
enabled: 0
settings:
CPU: x86
Linux64:
enabled: 0
settings:
CPU: x86_64
OSXIntel:
enabled: 1
settings:
CPU: AnyCPU
OSXIntel64:
enabled: 1
settings:
CPU: AnyCPU
OSXUniversal:
enabled: 1
settings:
CPU: AnyCPU
Win:
enabled: 0
settings:
CPU: AnyCPU
Win64:
enabled: 0
settings:
CPU: AnyCPU
iOS:
enabled: 0
settings:
CompileFlags:
FrameworkDependencies:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>25F80</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>WebView</string>
<key>CFBundleIdentifier</key>
<string>net.gree.unitywebview.WebView</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>WebView</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>25F70</string>
<key>DTPlatformName</key>
<string>macosx</string>
<key>DTPlatformVersion</key>
<string>26.5</string>
<key>DTSDKBuild</key>
<string>25F70</string>
<key>DTSDKName</key>
<string>macosx26.5</string>
<key>DTXcode</key>
<string>2650</string>
<key>DTXcodeBuild</key>
<string>17F42</string>
<key>LSMinimumSystemVersion</key>
<string>10.13</string>
</dict>
</plist>
Binary file not shown.
@@ -0,0 +1,128 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>files</key>
<dict>
<key>Resources/InfoPlist.strings</key>
<data>
MiLKDDnrUKr4EmuvhS5VQwxHGK8=
</data>
</dict>
<key>files2</key>
<dict>
<key>Resources/InfoPlist.strings</key>
<dict>
<key>hash2</key>
<data>
Oc8u4Ht7Mz58F50L9NeYpbcq9qTlhPUeZCcDu/pPyCg=
</data>
</dict>
</dict>
<key>rules</key>
<dict>
<key>^Resources/</key>
<true/>
<key>^Resources/.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^Resources/.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^Resources/Base\.lproj/</key>
<dict>
<key>weight</key>
<real>1010</real>
</dict>
<key>^version.plist$</key>
<true/>
</dict>
<key>rules2</key>
<dict>
<key>.*\.dSYM($|/)</key>
<dict>
<key>weight</key>
<real>11</real>
</dict>
<key>^(.*/)?\.DS_Store$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>2000</real>
</dict>
<key>^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/</key>
<dict>
<key>nested</key>
<true/>
<key>weight</key>
<real>10</real>
</dict>
<key>^.*</key>
<true/>
<key>^Info\.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^PkgInfo$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^Resources/</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
<key>^Resources/.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^Resources/.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^Resources/Base\.lproj/</key>
<dict>
<key>weight</key>
<real>1010</real>
</dict>
<key>^[^/]+$</key>
<dict>
<key>nested</key>
<true/>
<key>weight</key>
<real>10</real>
</dict>
<key>^embedded\.provisionprofile$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
<key>^version\.plist$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
</dict>
</dict>
</plist>
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9a69d5fe42677e84b8100f858cb66df7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0763797fead754049b4255cee0993cb7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+4
View File
@@ -0,0 +1,4 @@
Place the Windows WebView plugin DLL here:
WebView.dll (64-bit, built from plugins/Windows)
Build instructions: see plugins/Windows/README.md
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: f62969be983297d4aa100a72a1ef672d
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.
@@ -0,0 +1,70 @@
fileFormatVersion: 2
guid: 8c2ac249de280af4ca5514719b5a934a
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 1
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
:
second:
enabled: 0
settings: {}
- first:
: Any
second:
enabled: 0
settings:
Exclude Android: 1
Exclude Editor: 0
Exclude Linux64: 0
Exclude OSXUniversal: 0
Exclude Win: 1
Exclude Win64: 0
- first:
Android: Android
second:
enabled: 0
settings:
CPU: ARMv7
- first:
Editor: Editor
second:
enabled: 1
settings:
CPU: x86_64
DefaultValueInitialized: true
OS: Windows
- first:
Standalone: Linux64
second:
enabled: 1
settings:
CPU: AnyCPU
- first:
Standalone: OSXUniversal
second:
enabled: 1
settings:
CPU: x86_64
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win64
second:
enabled: 1
settings:
CPU: x86_64
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 796e71d62d97fe14fa9d58010d2976fb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+4
View File
@@ -0,0 +1,4 @@
Place the Windows WebView plugin DLL here:
WebView.dll (32-bit, built from plugins/Windows)
Build instructions: see plugins/Windows/README.md
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ea032e1e67ffb2845b15ed2d0ca48d7a
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.
@@ -0,0 +1,70 @@
fileFormatVersion: 2
guid: ed66942567a0baa4e99daba51749d1c5
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 1
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
:
second:
enabled: 0
settings: {}
- first:
: Any
second:
enabled: 0
settings:
Exclude Android: 1
Exclude Editor: 0
Exclude Linux64: 0
Exclude OSXUniversal: 0
Exclude Win: 0
Exclude Win64: 1
- first:
Android: Android
second:
enabled: 0
settings:
CPU: ARMv7
- first:
Editor: Editor
second:
enabled: 1
settings:
CPU: x86
DefaultValueInitialized: true
OS: Windows
- first:
Standalone: Linux64
second:
enabled: 1
settings:
CPU: AnyCPU
- first:
Standalone: OSXUniversal
second:
enabled: 1
settings:
CPU: x86_64
- first:
Standalone: Win
second:
enabled: 1
settings:
CPU: x86
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: None
userData:
assetBundleName:
assetBundleVariant:
+101 -10
View File
@@ -129,6 +129,7 @@ extern "C" void UnitySendMessage(const char *, const char *, const char *);
UIView <WebViewProtocol> *webView;
NSString *gameObjectName;
NSMutableDictionary *customRequestHeader;
BOOL googleAppRedirectionEnabled;
BOOL alertDialogEnabled;
NSRegularExpression *allowRegex;
NSRegularExpression *denyRegex;
@@ -154,6 +155,7 @@ static NSMutableArray *_instances = [[NSMutableArray alloc] init];
gameObjectName = [NSString stringWithUTF8String:gameObjectName_];
customRequestHeader = [[NSMutableDictionary alloc] init];
googleAppRedirectionEnabled = false;
alertDialogEnabled = true;
allowRegex = nil;
denyRegex = nil;
@@ -169,7 +171,8 @@ static NSMutableArray *_instances = [[NSMutableArray alloc] init];
WKUserContentController *controller = [[WKUserContentController alloc] init];
[controller addScriptMessageHandler:[[WeakScriptMessageDelegate alloc] initWithDelegate:self] name:@"unityControl"];
[controller addScriptMessageHandler:[[WeakScriptMessageDelegate alloc] initWithDelegate:self] name:@"saveDataURL"];
NSString *str = @"\
{
NSString *str = @"\
window.Unity = { \
call: function(msg) { \
window.webkit.messageHandlers.unityControl.postMessage(msg); \
@@ -179,8 +182,11 @@ window.Unity = { \
} \
}; \
";
WKUserScript *script = [[WKUserScript alloc] initWithSource:str injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES];
[controller addUserScript:script];
}
if (!zoom) {
str = [str stringByAppendingString:@"\
NSString *str = @"\
(function() { \
var meta = document.querySelector('meta[name=viewport]'); \
if (meta == null) { \
@@ -191,12 +197,10 @@ window.Unity = { \
var head = document.getElementsByTagName('head')[0]; \
head.appendChild(meta); \
})(); \
"
];
";
WKUserScript *script = [[WKUserScript alloc] initWithSource:str injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
[controller addUserScript:script];
}
WKUserScript *script
= [[WKUserScript alloc] initWithSource:str injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
[controller addUserScript:script];
configuration.userContentController = controller;
configuration.allowsInlineMediaPlayback = true;
if (@available(iOS 10.0, *)) {
@@ -267,6 +271,12 @@ window.Unity = { \
[view addSubview:webView];
//set webview for Unity 6 accessibility hierarchy
NSMutableArray<UIAccessibilityElement *> *accessibilityElements
= view.accessibilityElements ? [view.accessibilityElements mutableCopy] : [NSMutableArray array];
[accessibilityElements addObject:(UIAccessibilityElement *)webView];
view.accessibilityElements = accessibilityElements;
return self;
}
@@ -284,6 +294,13 @@ window.Unity = { \
[webView0 stopLoading];
[webView0 removeFromSuperview];
[webView0 removeObserver:self forKeyPath:@"loading"];
//remove the WebViewObject from Unity hierarchy tree
UIView *view = UnityGetGLViewController().view;
NSMutableArray<UIAccessibilityElement *> *accessibilityElements
= view.accessibilityElements ? [view.accessibilityElements mutableCopy] : [NSMutableArray array];
[accessibilityElements removeObject: (UIAccessibilityElement *)webView0];
view.accessibilityElements = accessibilityElements;
}
basicAuthPassword = nil;
basicAuthUserName = nil;
@@ -306,6 +323,42 @@ window.Unity = { \
}];
}
+ (void)clearCookie:(const char *)name of:(const char *)url
{
NSURL *nsurl = [NSURL URLWithString:[[NSString alloc] initWithUTF8String:url]];
if (nsurl == nil) {
return;
}
NSString *nsname = [NSString stringWithUTF8String:name];
if (@available(iOS 9.0, *)) {
WKHTTPCookieStore *cookieStore = WKWebsiteDataStore.defaultDataStore.httpCookieStore;
[cookieStore
getAllCookies:^(NSArray<NSHTTPCookie *> *array) {
[array
enumerateObjectsUsingBlock:^(NSHTTPCookie *cookie, NSUInteger idx, BOOL *stop) {
if ([cookie.name isEqualToString:nsname]
&& [cookie.domain isEqualToString:nsurl.host]
&& [cookie.path isEqualToString:nsurl.path]) {
[cookieStore deleteCookie:cookie completionHandler:^{}];
}
}];
}];
} else {
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
if (cookieStorage == nil) {
// cf. https://stackoverflow.com/questions/33876295/nshttpcookiestorage-sharedhttpcookiestorage-comes-up-empty-in-10-11
cookieStorage = [NSHTTPCookieStorage sharedCookieStorageForGroupContainerIdentifier:@"Cookies"];
}
[[cookieStorage cookies] enumerateObjectsUsingBlock:^(NSHTTPCookie *cookie, NSUInteger idx, BOOL *stop) {
if ([cookie.name isEqualToString:nsname]
&& [cookie.domain isEqualToString:nsurl.host]
&& [cookie.path isEqualToString:nsurl.path]) {
[cookieStorage deleteCookie:cookie];
}
}];
}
}
+ (void)clearCookies
{
[CWebViewPlugin resetSharedProcessPool];
@@ -537,7 +590,11 @@ window.Unity = { \
return;
}
if ([url rangeOfString:@"//itunes.apple.com/"].location != NSNotFound) {
[[UIApplication sharedApplication] openURL:nsurl];
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:nsurl options:@{} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:nsurl];
}
decisionHandler(WKNavigationActionPolicyCancel);
return;
} else if ([url hasPrefix:@"unity:"]) {
@@ -554,7 +611,11 @@ window.Unity = { \
&& ![url hasPrefix:@"http:"]
&& ![url hasPrefix:@"https:"]) {
if([[UIApplication sharedApplication] canOpenURL:nsurl]) {
[[UIApplication sharedApplication] openURL:nsurl];
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:nsurl options:@{} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:nsurl];
}
}
decisionHandler(WKNavigationActionPolicyCancel);
return;
@@ -568,7 +629,7 @@ window.Unity = { \
if (navigationAction.targetFrame != nil && navigationAction.targetFrame.isMainFrame) {
// If the custom header is not attached, give it and make a request again.
if (![self isSetupedCustomHeader:[navigationAction request]]) {
NSLog(@"navi ... %@", navigationAction);
//NSLog(@"navi ... %@", navigationAction);
[wkWebView loadRequest:[self constructionCustomHeader:navigationAction.request]];
decisionHandler(WKNavigationActionPolicyCancel);
return;
@@ -576,6 +637,14 @@ window.Unity = { \
}
}
UnitySendMessage([gameObjectName UTF8String], "CallOnStarted", [url UTF8String]);
// cf. https://stackoverflow.com/questions/37086605/disable-wkwebview-for-opening-links-to-redirect-to-apps-installed-on-my-iphone/76948270#76948270
if (!googleAppRedirectionEnabled
&& [url hasPrefix:@"https://www.google.com/"]
&& navigationAction.navigationType == WKNavigationTypeLinkActivated) {
[webView load:navigationAction.request];
decisionHandler(WKNavigationActionPolicyCancel);
return;
}
decisionHandler(WKNavigationActionPolicyAllow);
}
@@ -737,6 +806,13 @@ window.Unity = { \
webView.userInteractionEnabled = enabled;
}
- (void)setGoogleAppRedirectionEnabled:(BOOL)enabled
{
if (webView == nil)
return;
googleAppRedirectionEnabled = enabled;
}
- (void)setAlertDialogEnabled:(BOOL)enabled
{
alertDialogEnabled = enabled;
@@ -951,6 +1027,7 @@ extern "C" {
void *instance, float left, float top, float right, float bottom, BOOL relative);
void _CWebViewPlugin_SetVisibility(void *instance, BOOL visibility);
void _CWebViewPlugin_SetInteractionEnabled(void *instance, BOOL enabled);
void _CWebViewPlugin_SetGoogleAppRedirectionEnabled(void *instance, BOOL enabled);
void _CWebViewPlugin_SetAlertDialogEnabled(void *instance, BOOL visibility);
void _CWebViewPlugin_SetScrollbarsVisibility(void *instance, BOOL visibility);
void _CWebViewPlugin_SetScrollBounceEnabled(void *instance, BOOL enabled);
@@ -967,6 +1044,7 @@ extern "C" {
void _CWebViewPlugin_AddCustomHeader(void *instance, const char *headerKey, const char *headerValue);
void _CWebViewPlugin_RemoveCustomHeader(void *instance, const char *headerKey);
void _CWebViewPlugin_ClearCustomHeader(void *instance);
void _CWebViewPlugin_ClearCookie(const char *url, const char *name);
void _CWebViewPlugin_ClearCookies();
void _CWebViewPlugin_SaveCookies();
void _CWebViewPlugin_GetCookies(void *instance, const char *url);
@@ -1040,6 +1118,14 @@ void _CWebViewPlugin_SetInteractionEnabled(void *instance, BOOL enabled)
[webViewPlugin setInteractionEnabled:enabled];
}
void _CWebViewPlugin_SetGoogleAppRedirectionEnabled(void *instance, BOOL enabled)
{
if (instance == NULL)
return;
CWebViewPlugin *webViewPlugin = (__bridge CWebViewPlugin *)instance;
[webViewPlugin setGoogleAppRedirectionEnabled:enabled];
}
void _CWebViewPlugin_SetAlertDialogEnabled(void *instance, BOOL enabled)
{
if (instance == NULL)
@@ -1168,6 +1254,11 @@ void _CWebViewPlugin_ClearCustomHeader(void *instance)
[webViewPlugin clearCustomRequestHeader];
}
void _CWebViewPlugin_ClearCookie(const char *url, const char *name)
{
[CWebViewPlugin clearCookie:name of:url];
}
void _CWebViewPlugin_ClearCookies()
{
[CWebViewPlugin clearCookies];
+93 -11
View File
@@ -182,6 +182,7 @@ extern "C" void UnitySendMessage(const char *, const char *, const char *);
UIView <WebViewProtocol> *webView;
NSString *gameObjectName;
NSMutableDictionary *customRequestHeader;
BOOL googleAppRedirectionEnabled;
BOOL alertDialogEnabled;
NSRegularExpression *allowRegex;
NSRegularExpression *denyRegex;
@@ -207,6 +208,7 @@ static NSMutableArray *_instances = [[NSMutableArray alloc] init];
gameObjectName = [NSString stringWithUTF8String:gameObjectName_];
customRequestHeader = [[NSMutableDictionary alloc] init];
googleAppRedirectionEnabled = false;
alertDialogEnabled = true;
allowRegex = nil;
denyRegex = nil;
@@ -222,7 +224,8 @@ static NSMutableArray *_instances = [[NSMutableArray alloc] init];
WKUserContentController *controller = [[WKUserContentController alloc] init];
[controller addScriptMessageHandler:[[WeakScriptMessageDelegate alloc] initWithDelegate:self] name:@"unityControl"];
[controller addScriptMessageHandler:[[WeakScriptMessageDelegate alloc] initWithDelegate:self] name:@"saveDataURL"];
NSString *str = @"\
{
NSString *str = @"\
window.Unity = { \
call: function(msg) { \
window.webkit.messageHandlers.unityControl.postMessage(msg); \
@@ -232,8 +235,11 @@ window.Unity = { \
} \
}; \
";
WKUserScript *script = [[WKUserScript alloc] initWithSource:str injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES];
[controller addUserScript:script];
}
if (!zoom) {
str = [str stringByAppendingString:@"\
NSString *str = @"\
(function() { \
var meta = document.querySelector('meta[name=viewport]'); \
if (meta == null) { \
@@ -244,12 +250,10 @@ window.Unity = { \
var head = document.getElementsByTagName('head')[0]; \
head.appendChild(meta); \
})(); \
"
];
";
WKUserScript *script = [[WKUserScript alloc] initWithSource:str injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
[controller addUserScript:script];
}
WKUserScript *script
= [[WKUserScript alloc] initWithSource:str injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
[controller addUserScript:script];
configuration.userContentController = controller;
configuration.allowsInlineMediaPlayback = true;
if (@available(iOS 10.0, *)) {
@@ -368,6 +372,42 @@ window.Unity = { \
}];
}
+ (void)clearCookie:(const char *)name of:(const char *)url
{
NSURL *nsurl = [NSURL URLWithString:[[NSString alloc] initWithUTF8String:url]];
if (nsurl == nil) {
return;
}
NSString *nsname = [NSString stringWithUTF8String:name];
if (@available(iOS 9.0, *)) {
WKHTTPCookieStore *cookieStore = WKWebsiteDataStore.defaultDataStore.httpCookieStore;
[cookieStore
getAllCookies:^(NSArray<NSHTTPCookie *> *array) {
[array
enumerateObjectsUsingBlock:^(NSHTTPCookie *cookie, NSUInteger idx, BOOL *stop) {
if ([cookie.name isEqualToString:nsname]
&& [cookie.domain isEqualToString:nsurl.host]
&& [cookie.path isEqualToString:nsurl.path]) {
[cookieStore deleteCookie:cookie completionHandler:^{}];
}
}];
}];
} else {
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
if (cookieStorage == nil) {
// cf. https://stackoverflow.com/questions/33876295/nshttpcookiestorage-sharedhttpcookiestorage-comes-up-empty-in-10-11
cookieStorage = [NSHTTPCookieStorage sharedCookieStorageForGroupContainerIdentifier:@"Cookies"];
}
[[cookieStorage cookies] enumerateObjectsUsingBlock:^(NSHTTPCookie *cookie, NSUInteger idx, BOOL *stop) {
if ([cookie.name isEqualToString:nsname]
&& [cookie.domain isEqualToString:nsurl.host]
&& [cookie.path isEqualToString:nsurl.path]) {
[cookieStorage deleteCookie:cookie];
}
}];
}
}
+ (void)clearCookies
{
[CWebViewPlugin resetSharedProcessPool];
@@ -606,7 +646,11 @@ window.Unity = { \
return NO;
}
if ([url rangeOfString:@"//itunes.apple.com/"].location != NSNotFound) {
[[UIApplication sharedApplication] openURL:nsurl];
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:nsurl options:@{} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:nsurl];
}
return NO;
} else if ([url hasPrefix:@"unity:"]) {
UnitySendMessage([gameObjectName UTF8String], "CallFromJS", [[url substringFromIndex:6] UTF8String]);
@@ -652,7 +696,11 @@ window.Unity = { \
return;
}
if ([url rangeOfString:@"//itunes.apple.com/"].location != NSNotFound) {
[[UIApplication sharedApplication] openURL:nsurl];
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:nsurl options:@{} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:nsurl];
}
decisionHandler(WKNavigationActionPolicyCancel);
return;
} else if ([url hasPrefix:@"unity:"]) {
@@ -669,7 +717,11 @@ window.Unity = { \
&& ![url hasPrefix:@"http:"]
&& ![url hasPrefix:@"https:"]) {
if([[UIApplication sharedApplication] canOpenURL:nsurl]) {
[[UIApplication sharedApplication] openURL:nsurl];
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:nsurl options:@{} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:nsurl];
}
}
decisionHandler(WKNavigationActionPolicyCancel);
return;
@@ -683,7 +735,7 @@ window.Unity = { \
if (navigationAction.targetFrame != nil && navigationAction.targetFrame.isMainFrame) {
// If the custom header is not attached, give it and make a request again.
if (![self isSetupedCustomHeader:[navigationAction request]]) {
NSLog(@"navi ... %@", navigationAction);
//NSLog(@"navi ... %@", navigationAction);
[wkWebView loadRequest:[self constructionCustomHeader:navigationAction.request]];
decisionHandler(WKNavigationActionPolicyCancel);
return;
@@ -691,6 +743,14 @@ window.Unity = { \
}
}
UnitySendMessage([gameObjectName UTF8String], "CallOnStarted", [url UTF8String]);
// cf. https://stackoverflow.com/questions/37086605/disable-wkwebview-for-opening-links-to-redirect-to-apps-installed-on-my-iphone/76948270#76948270
if (!googleAppRedirectionEnabled
&& [url hasPrefix:@"https://www.google.com/"]
&& navigationAction.navigationType == WKNavigationTypeLinkActivated) {
[webView load:navigationAction.request];
decisionHandler(WKNavigationActionPolicyCancel);
return;
}
decisionHandler(WKNavigationActionPolicyAllow);
}
@@ -852,6 +912,13 @@ window.Unity = { \
webView.userInteractionEnabled = enabled;
}
- (void)setGoogleAppRedirectionEnabled:(BOOL)enabled
{
if (webView == nil)
return;
googleAppRedirectionEnabled = enabled;
}
- (void)setAlertDialogEnabled:(BOOL)enabled
{
alertDialogEnabled = enabled;
@@ -1044,6 +1111,7 @@ extern "C" {
void *instance, float left, float top, float right, float bottom, BOOL relative);
void _CWebViewPlugin_SetVisibility(void *instance, BOOL visibility);
void _CWebViewPlugin_SetInteractionEnabled(void *instance, BOOL enabled);
void _CWebViewPlugin_SetGoogleAppRedirectionEnabled(void *instance, BOOL enabled);
void _CWebViewPlugin_SetAlertDialogEnabled(void *instance, BOOL visibility);
void _CWebViewPlugin_SetScrollbarsVisibility(void *instance, BOOL visibility);
void _CWebViewPlugin_SetScrollBounceEnabled(void *instance, BOOL enabled);
@@ -1060,6 +1128,7 @@ extern "C" {
void _CWebViewPlugin_AddCustomHeader(void *instance, const char *headerKey, const char *headerValue);
void _CWebViewPlugin_RemoveCustomHeader(void *instance, const char *headerKey);
void _CWebViewPlugin_ClearCustomHeader(void *instance);
void _CWebViewPlugin_ClearCookie(const char *url, const char *name);
void _CWebViewPlugin_ClearCookies();
void _CWebViewPlugin_SaveCookies();
void _CWebViewPlugin_GetCookies(void *instance, const char *url);
@@ -1131,6 +1200,14 @@ void _CWebViewPlugin_SetInteractionEnabled(void *instance, BOOL enabled)
[webViewPlugin setInteractionEnabled:enabled];
}
void _CWebViewPlugin_SetGoogleAppRedirectionEnabled(void *instance, BOOL enabled)
{
if (instance == NULL)
return;
CWebViewPlugin *webViewPlugin = (__bridge CWebViewPlugin *)instance;
[webViewPlugin setGoogleAppRedirectionEnabled:enabled];
}
void _CWebViewPlugin_SetAlertDialogEnabled(void *instance, BOOL enabled)
{
if (instance == NULL)
@@ -1259,6 +1336,11 @@ void _CWebViewPlugin_ClearCustomHeader(void *instance)
[webViewPlugin clearCustomRequestHeader];
}
void _CWebViewPlugin_ClearCookie(const char *url, const char *name)
{
[CWebViewPlugin clearCookie:name of:url];
}
void _CWebViewPlugin_ClearCookies()
{
[CWebViewPlugin clearCookies];