native_manager.ts 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { _decorator, Component, Node, sys, native } from 'cc';
  2. import { GameMng } from './GameMng';
  3. import { UIManager } from './gcommon/UIManager';
  4. import { msgManager } from './socket/msgManager';
  5. import { Tools } from './Tools';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('native_manager')
  8. export class native_manager {
  9. public static wxLogin(){
  10. UIManager.AddPrefab(GameMng.Instance.uiloading)
  11. if("ANDROID"==sys.platform){
  12. native.jsbBridgeWrapper.dispatchEventToNative("send_ios_login");
  13. native.jsbBridgeWrapper.removeNativeEventListener("receive_ios_login",native_manager.ios_login)
  14. native.jsbBridgeWrapper.addNativeEventListener("receive_ios_login",native_manager.ios_login);
  15. }else if("IOS"==sys.platform){
  16. native.jsbBridgeWrapper.dispatchEventToNative("send_ios_login");
  17. native.jsbBridgeWrapper.removeNativeEventListener("receive_ios_login",native_manager.ios_login)
  18. native.jsbBridgeWrapper.addNativeEventListener("receive_ios_login",native_manager.ios_login);
  19. }
  20. }
  21. public static ios_login(jsonStr: string): void {
  22. var json_ = JSON.parse(jsonStr);
  23. console.log("wxLogin",jsonStr)
  24. if(jsonStr!=""){
  25. for (const key in json_) {
  26. if (Object.prototype.hasOwnProperty.call(json_, key)) {
  27. const element = json_[key];
  28. console.log("wxLogin",element)
  29. }
  30. }
  31. msgManager.wxlogin(json_.nickname,json_.openId,json_.sex,json_.property,json_.city,json_.country,json_.headimgurl)
  32. }
  33. }
  34. public static share(){
  35. if("ANDROID"==sys.platform){
  36. setTimeout(() => {
  37. var o = native.reflection.callStaticMethod("com/cocos/game/AppActivity", "shareWx", "(Ljava/lang/String;)V",Tools.getShareObj());
  38. }, 1000);
  39. }else if("IOS"==sys.platform){
  40. native.jsbBridgeWrapper.dispatchEventToNative("shareWx",Tools.getShareObj());
  41. }
  42. }
  43. public static check_jump_info(){
  44. native_manager.recv_jump_info();
  45. if("ANDROID"==sys.platform){
  46. native.jsbBridgeWrapper.dispatchEventToNative("check_jump_info");
  47. }else if("IOS"==sys.platform){
  48. native.jsbBridgeWrapper.dispatchEventToNative("check_jump_info");
  49. }
  50. }
  51. public static recv_jump_info_call(jsonStr: string): void {
  52. var json_ = JSON.parse(jsonStr);
  53. console.log("recv_jump_info_call",jsonStr)
  54. }
  55. public static recv_jump_info(){
  56. if("ANDROID"==sys.platform){
  57. native.jsbBridgeWrapper.removeNativeEventListener("recv_jump_info",native_manager.recv_jump_info_call);
  58. native.jsbBridgeWrapper.addNativeEventListener("recv_jump_info",native_manager.recv_jump_info_call);
  59. }else if("IOS"==sys.platform){
  60. native.jsbBridgeWrapper.removeNativeEventListener("recv_jump_info",native_manager.recv_jump_info_call);
  61. native.jsbBridgeWrapper.addNativeEventListener("recv_jump_info",native_manager.recv_jump_info_call);
  62. }
  63. }
  64. public static hideSplash(){
  65. if("ANDROID"==sys.platform){
  66. setTimeout(() => {
  67. var o = native.reflection.callStaticMethod("com/cocos/game/AppActivity", "hideSplash", "()V");
  68. }, 1000);
  69. }else if("IOS"==sys.platform){
  70. native.jsbBridgeWrapper.dispatchEventToNative("hideSplash");
  71. }
  72. }
  73. }