Code Monkey home page Code Monkey logo

cocos_desktop_webview's Introduction

cocos-desktop-webview

cocos UIWebView在windows和mac平台上的适配

环境配置

  1. source文件夹下为新增文件,按路径拷贝到响应位置,并加到对应工程项目中。
  2. mac项目需要在主工程和cocos工程中添加WebKit.framework依赖
  3. 在相关的平台判断中,加入新增的两个平台,包括以下几个文件
  • UIWebView.h
//old
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) && !defined(CC_PLATFORM_OS_TVOS)

//new
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) && !defined(CC_PLATFORM_OS_TVOS)
  • UIWebView.cpp
//old
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
#include "ui/UIWebViewImpl-android.h"
#include "ui/UIWebView-inl.h"
#endif
   
//new
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
#include "ui/UIWebViewImpl-android.h"
#include "ui/UIWebView-inl.h"
   
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#include "ui/UIWebViewImpl-win32.h"
#include "ui/UIWebView-inl.h"
#endif
  • UIWebView.mm
//old
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && !defined(CC_PLATFORM_OS_TVOS)
 
//new
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && !defined(CC_PLATFORM_OS_TVOS)

  • CocosGUI.h
//old
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
#include "ui/UIWebView.h"
#endif

//new
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
#include "ui/UIWebView.h"
#endif
  1. 脚本导出

    以lua为例,也是在相关文件判断中添加平台,包括以下文件

    • scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.cpp

    • scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.hpp

    • scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.cpp

    • scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.hpp

    • scripting/lua-bindings/manual/ui/lua_cocos2dx_ui_manual.cpp

       //old
       #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && !defined(CC_TARGET_OS_TVOS)
       #include "scripting/lua-bindings/auto/lua_cocos2dx_experimental_video_auto.hpp"
       #include "scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_video_manual.hpp"
       #include "scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.hpp"
       #include "scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.hpp"
       #endif
       
       //new
       #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && !defined(CC_TARGET_OS_TVOS)
       #include "scripting/lua-bindings/auto/lua_cocos2dx_experimental_video_auto.hpp"
       #include "scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_video_manual.hpp"
       #endif
       
       #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) && !defined(CC_TARGET_OS_TVOS)
       #include "scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.hpp"
       #include "scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.hpp"
       #endif
      
       //old
       #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && !defined(CC_TARGET_OS_TVOS)
       	register_all_cocos2dx_experimental_video(L);
       	register_all_cocos2dx_experimental_video_manual(L);
       	register_all_cocos2dx_experimental_webview(L);
       	register_all_cocos2dx_experimental_webview_manual(L);
       #endif
       
       //new
       #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && !defined(CC_TARGET_OS_TVOS)
       	register_all_cocos2dx_experimental_video(L);
       	register_all_cocos2dx_experimental_video_manual(L);
       #endif
       
       #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) && !defined(CC_TARGET_OS_TVOS)
      	register_all_cocos2dx_experimental_webview(L);
      	register_all_cocos2dx_experimental_webview_manual(L);
       #endif
      
      

常见问题

  1. Mac打不开https网址:Info.plist中添加NSAppTransportSecurity配置,参考苹果文档翻译 iOS10 NSAppTransportSecurity
  2. windows默认使用的是IE7内核,不少js特性不支持,可以在注册表[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION]中新加dword值,键为你的应用程序名字,如xxxx.exe,值为对应ie版本,2af9是IE11
  3. TODO
  • setJavascriptInterfaceScheme接口支持

效果图

cocos_desktop_webview's People

Contributors

lyzz0612 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.