[己解决]cocosCreator 构建IOS,j s调用原生方法没有问题!jsb-webview.js not found

cocosCreator 构建IOS,增加腾讯语音识别SDK,增加js调用原生方法没有问题!增加原生回调JS出问题!

  • Creator 版本:2.0.9

  • 目标平台: iOS

  • 详细报错信息,包含调用堆栈:
    2019-09-20 09:04:58.665386+0800 CRCloud-mobile[2502:586407] [DYMTLInitPlatform] platform initialization successful
    2019-09-20 09:04:58.737250+0800 CRCloud-mobile[2502:586208] [NetworkInfo] Signal strength query returned error: Error Domain=NSPOSIXErrorDomain Code=13 “Permission denied”, descriptor: <CTServiceDescriptor 0x280604d20, domain=1, instance=1>
    2019-09-20 09:04:58.795267+0800 CRCloud-mobile[2502:586208] Reachability Flag Status: -R ------- networkStatusForFlags
    2019-09-20 09:04:58.976466+0800 CRCloud-mobile[2502:586208] (null)
    Initializing JavaScriptCore
    JS: Enable batch GL commands optimization!
    ScriptEngine::onGetStringFromFile ./jsb-webview.js not found, possible missing file.
    ScriptEngine::runScript script ./jsb-webview.js, buffer is empty!
    [ERROR] Failed to invoke require, location: /Users/hst-home/Desktop/CocosCreator.app/Contents/Resources/cocos2d-x/cocos/scripting/js-bindings/manual/jsb_global.cpp:292
    ScriptEngine::onGetStringFromFile ./jsb-editbox.js not found, possible missing file.
    ScriptEngine::runScript script ./jsb-editbox.js, buffer is empty!
    [ERROR] Failed to invoke require, location: /Users/hst-home/Desktop/CocosCreator.app/Contents/Resources/cocos2d-x/cocos/scripting/js-bindings/manual/jsb_global.cpp:292
    ScriptEngine::onGetStringFromFile ./jsb-dragonbones.js not found, possible missing file.
    ScriptEngine::runScript script ./jsb-dragonbones.js, buffer is empty!
    [ERROR] Failed to invoke require, location: /Users/hst-home/Desktop/CocosCreator.app/Contents/Resources/cocos2d-x/cocos/scripting/js-bindings/manual/jsb_global.cpp:292
    ScriptEngine::onGetStringFromFile ./jsb-spine-skeleton.js not found, possible missing file.
    ScriptEngine::runScript script ./jsb-spine-skeleton.js, buffer is empty!
    [ERROR] Failed to invoke require, location: /Users/hst-home/Desktop/CocosCreator.app/Contents/Resources/cocos2d-x/cocos/scripting/js-bindings/manual/jsb_global.cpp:292
    ScriptEngine::onGetStringFromFile ./jsb-spine-assembler.js not found, possible missing file.
    ScriptEngine::runScript script ./jsb-spine-assembler.js, buffer is empty!
    [ERROR] Failed to invoke require, location: /Users/hst-home/Desktop/CocosCreator.app/Contents/Resources/cocos2d-x/cocos/scripting/js-bindings/manual/jsb_global.cpp:292
    glGetIntegerv: pname: 0x8b4c
    JS: Cocos Creator v2.0.9
    JS: Create unpacker 07137bebb for 02delMVqdBD70a/HSD99FK
    libpng warning: Interlace handling should be turned on when using png_read_image
    JS: LoadScene 89LqD38GdLjrb3hKGx1WtR: 956.264ms
    JS: Success to load scene: db://assets/scene/Lesson-1.fire
    JS: fadeFromWhite
    JS: preloadScene Lesson-2 success!
    ERROR: ReferenceError: Can’t find variable: cb, location: src/project.js:935:25
    STACK:
    jsCallIosNative@src/project.js:935:25
    onEventSpeechRecognition@src/project.js:308:29
    invoke@src/cocos2d-jsb.js:17990:11
    src/cocos2d-jsb.js:5925:85
    dispatchEvent@src/cocos2d-jsb.js:5939:3
    P@src/cocos2d-jsb.js:5244:16
    _onTouchEventCallback@src/cocos2d-jsb.js:12641:33
    _dispatchEventToListeners@src/cocos2d-jsb.js:12716:115
    _dispatchTouchEvent@src/cocos2d-jsb.js:12672:31
    dispatchEvent@src/cocos2d-jsb.js:12911:25
    handleTouchesEnd@src/cocos2d-jsb.js:16295:16
    touchend@src/cocos2d-jsb.js:16486:19
    src/cocos2d-jsb.js:16517:2
    dispatchEvent@jsb-adapter/jsb-builtin.js:2805:39
    jsb-adapter/jsb-builtin.js:2844:33

  • 重现方式:100%

  • 之前哪个版本是正常的 :

  • 手机型号 12:

增加腾讯语音识别功能后出现!增加代码方式如下:
`@interface AppController : NSObject
{
}
+(void)jsCallNativeRealTimeRecognizer:(NSString*) param;
+(void)jsCallNativeRealTimeRecognizerStop;
@property(nonatomic, readonly) RootViewController* viewController;

@end +(void)jsCallNativeRealTimeRecognizer:(NSString*) param
{
if(!QCloudInstant)
{
QCloudInstant = [[MyQCloudDelegate alloc] init];
}
[QCloudInstant realTimeRecognizer:param];
}
+(void)jsCallNativeRealTimeRecognizerStop
{
if(QCloudInstant)
{
[QCloudInstant stopRealTimeRecognizer];
}
}`

QCloudInstant 对象源文件 放在和AppController同级

QCloudInstant 可能引起 错误的 源代码 在没有增加 原生调用js之前 是没有问题的!
#include “cocos/scripting/js-bindings/jswrapper/SeApi.h”
#import “cocos2d.h”

  • (void)realTimeRecognizerOnSliceRecognize:(QCloudRealTimeRecognizer *)recognizer response:(QCloudRealTimeResponse *)response
    {
    if (QCloudRealTimeResponseCodeOk == response.code) {
    std::string jsCallStr = cocos2d::StringUtils::format(“NativeHelper.nativeIosCallJsMain(”%s");",[response.recognizedText UTF8String] );
    NSLog(@“jsCallStr = %s”, jsCallStr.c_str());
    se::ScriptEngine::getInstance()->evalString(jsCallStr.c_str());

    }
    }

js端代码
onLoad () {
let testBtn = cc.find(‘Canvas/button’);
testBtn.on(‘touchend’, this.onEventSpeechRecognition, this);

    window.NativeHelper = this.node.getComponent("NativeHelper");
    
},

onEventSpeechRecognition(){
//if(cc.sys.os === cc.sys.OS_IOS){
NativeHelper.jsCallIosNative(
“AppController”,
“jsCallNativeRealTimeRecognizer:”,
“js call native [AppController jsCallNativeRealTimeRecognizer]”,
(msg)=>{
this.setNativeLable(msg);
}
);
//}
},

当时为了。减少WEB打包后的js大小。在设置项目的时候。把没有用的功能去掉了。想不到为将来原生端埋坑了。需要全部钩上!