Titanium 钛-侦听器回调属于不受支持的类型:\uu\n字典

Titanium 钛-侦听器回调属于不受支持的类型:\uu\n字典,titanium,appcelerator,Titanium,Appcelerator,我对iOS下的Tianium SDK>=6.1.0 GA和Ti.App.firevent有问题。在SDK 6.0.4 GA之前,使用Ti.App.firevent和JSON字典作为参数工作正常,但从6.1.0到最后一个GA(6.3.0),我收到以下消息: Listener callback is of a non-supported type: __NSDictionaryM 我在KrollBridge.m中看到这行代码,它可能会导致以下日志消息: - (void)fireEvent:(id)

我对iOS下的Tianium SDK>=6.1.0 GA和Ti.App.firevent有问题。在SDK 6.0.4 GA之前,使用Ti.App.firevent和JSON字典作为参数工作正常,但从6.1.0到最后一个GA(6.3.0),我收到以下消息:

Listener callback is of a non-supported type: __NSDictionaryM
我在KrollBridge.m中看到这行代码,它可能会导致以下日志消息:

- (void)fireEvent:(id)listener withObject:(id)obj remove:(BOOL)yn thisObject:(TiProxy*)thisObject_
{
    if (![listener isKindOfClass:[KrollCallback class]])
    {
        NSLog(@"[ERROR] listener callback is of a non-supported type: %@",[listener class]);
        return;
    }

    KrollEvent *event = [[KrollEvent alloc] initWithCallback:listener eventObject:obj thisObject:thisObject_];
    [context enqueue:event];
    [event release];
}
仅当我在设备上尝试应用程序时失败,在模拟器上工作正常

添加一些NSLog并运行应用程序:

控制台:

Simulator:
[DEBUG] :  Firing app event: event_test
[DEBUG] :  Listener type: KrollCallback
[DEBUG] :  OK

Device:
[DEBUG] :  Firing app event: event_test
[DEBUG] :  Listener type: __NSDictionaryM
[ERROR] :  Listener callback is of a non-supported type: __NSDictionaryM
代码:

我不知道为什么。我觉得这是6.1.0GA中引入的一个bug,它会一直复制到最后一个可用的GA

有什么建议吗?
谢谢

我想这是这里报告的相同问题,在SDK 6.3.0.GA中标记为已解决

一定要将您的Ti SDK更新到最新的6.3.0.GA,因为它比其他6.x版本更稳定


建议的解决方案: 请阅读此处为什么要避免使用以下步骤来设置全局事件侦听器以传递任何您想要的内容&请按照以下步骤进行操作

  • 在项目的app->lib文件夹中创建一个具有任意名称的js文件,比如说,events\u dispatcher.js
  • 在该文件中添加此代码行:
    module.exports=\uu.clone(Backbone.Events)
  • 现在,替换您的Ti.App.addEventListener('event\u test',fun')代码使用此代码:

    var eventHandler = require('events_dispatcher');
    
    eventHandler.on('event_test', fun);
    
    
    // to avoid duplication of adding the same event
    // make sure to remove this event when you close the controller
    // or you are planning to re-create the controller 
    
    eventHandler.off('event_test', fun);
    
  • 最后替换此代码
    Ti.App.firevent('event_test',数据:{“ID”:0,“Value”:“test”})使用此命令-
    需要('events\u dispatcher')。触发器('event\u test',数据:{“ID”:0,“Value”:“test”})


  • 此代码方法可能看起来不多,但它是最推荐的方法&最适合您替换Ti.App.firevent的所有需求的最佳解决方案。坚持下去&你将有一个安全的方法来调用任何类型数据的任何方法。

    我尝试使用6.3.0 GA,但结果相同。这似乎是一个尚未解决的fireEvent错误:(别担心。我添加了一种处理全局或应用程序范围内事件处理的新方法。我强烈建议您坚持使用我在回答中添加的新解决方案。使用它总是更安全的。
    var eventHandler = require('events_dispatcher');
    
    eventHandler.on('event_test', fun);
    
    
    // to avoid duplication of adding the same event
    // make sure to remove this event when you close the controller
    // or you are planning to re-create the controller 
    
    eventHandler.off('event_test', fun);