#include <iostream>
#include <string>
#include "JsbBridgeTest.h"
#import <Foundation/Foundation.h>
#import "cocos/platform/apple/JsbBridgeWrapper.h"
@implementation JsbBridgeTest{
}
-(id)init{
self = [super init];
JsbBridgeWrapper* m = [JsbBridgeWrapper sharedInstance];
OnScriptEventListener requestLabelContent = ^void(NSString* arg){
///////// 这里加了这行调用,运行时总是报错,不知道原因。//////
[self login];
////////////////////////////////////////////////////
JsbBridgeWrapper* m = [JsbBridgeWrapper sharedInstance];
[m dispatchEventToScript:@"changeLabelContent" arg:@"Charlotte"];
};
OnScriptEventListener requestLabelColor = ^void(NSString* arg){
JsbBridgeWrapper* m = [JsbBridgeWrapper sharedInstance];
[m dispatchEventToScript:@"changeLabelColor"];
};
OnScriptEventListener requestBtnColor = ^void(NSString* arg){
JsbBridgeWrapper* m = [JsbBridgeWrapper sharedInstance];
[m dispatchEventToScript:@"changeLightColor"];
};
[m addScriptEventListener:@"requestLabelContent" listener:requestLabelContent];
[m addScriptEventListener:@"requestLabelColor" listener:requestLabelColor];
[m addScriptEventListener:@"requestBtnColor" listener:requestBtnColor];
[m addScriptEventListener:@"removeJSCallback" listener:^void(NSString* arg){
JsbBridgeWrapper * m = [JsbBridgeWrapper sharedInstance];
[m removeAllListenersForEvent:@"requestBtnColor"];
}];
return self;
}
@end
以上是官方的 JsbBridgeTest.mm 代码,我上面在 block 中加了一行代码,注释位置处。 程序运行总是报错EXC_BAD_ACCESS,是啥原因?