gree / unity-webview

zlib License
2.28k stars 691 forks source link

I don't want to run Youtube app. #837

Open kamahiekama opened 2 years ago

kamahiekama commented 2 years ago

試用させて頂いています。ありがとうございます。1点質問があります。

iOS 端末で Youtube の URL を開くと、端末にインストールされている Youtube アプリが開いてしまいます。 このプログラム内の WebView で Youtube を表示させたいのですが、可能でしょうか?

KojiNakamaru commented 2 years ago

プロジェクト内に展開する形で取り込んでいただき、次のようにWebView.mmを変更すれば、WebView内でYouTubeが表示されるようになります。

--- Assets/Plugins/iOS/WebView.mm~  2022-08-03 00:10:20.000000000 +0900
+++ Assets/Plugins/iOS/WebView.mm   2022-09-02 15:10:51.000000000 +0900
@@ -440,7 +440,9 @@
         }
     }
     UnitySendMessage([gameObjectName UTF8String], "CallOnStarted", [url UTF8String]);
-    decisionHandler(WKNavigationActionPolicyAllow);
+    // cf. https://stackoverflow.com/questions/52403344/stop-wkwebview-redirecting-to-another-app-based-on-universal-link/52425266#52425266
+    //decisionHandler(WKNavigationActionPolicyAllow);
+    decisionHandler((WKNavigationActionPolicy)(WKNavigationActionPolicyAllow + 2));
 }

 - (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {