Titanium JIRA Archive
Appcelerator Modules (MOD)

[MOD-2249] Appcelerator module events stop firing

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionInvalid
Resolution Date2017-07-28T19:26:48.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
Reporterderick alt
AssigneeUnknown
Created2016-04-18T18:49:00.000+0000
Updated2018-08-06T17:37:00.000+0000

Description

* Create a native iOS module * In the module, fire an event, as seen below:
- (void) imageCaptured:(NSNotification *) notification
{
    NSLog(@"[INFO] module notified of image capture event");
    if ([self _hasListeners:'imageCaptured'])
        [self fireEvent:'imageCaptured' withObject:notification.userInfo];
    else
        NSLog(@"[INFO] if an image is captured, and there is no one there to listen for it, does an event get fired?");
}
* In Appcelerator, listen for this event:
mymodule.addEventListener('imageCaptured', function(e){
    Ti.API.info('image capture event caught in JS.);
});
* Sometimes the event will catch. You will see both lines in the console. Other times, you will see the first line in the console, but nothing else. No error, and no response in JS. http://stackoverflow.com/questions/36655410/appcelerator-module-events-stop-firing?noredirect=1#comment60966343_36655410

Comments

  1. derick alt 2016-04-20

    I was able to work around this issue for the time being by moving all events to my custom view, using [[self proxy] fireevent...]
  2. Sharif AbuDarda 2016-04-20

    Hello, Thanks for creating the JIRA ticket. Please attach the module project to this ticket for us to test it in our environment. It will be helpful to understand the issue properly if we were to investigate the project code. Also, please provide the full list of steps to follow. Regards, Sharif.
  3. derick alt 2016-04-20

    I am not permitted to share the full source code, as it is proprietary. The steps to reproduce should be quite simple. 1. Create a native iOS module 2. Create a view and view proxy in the module 3. From the view, post a notification like so... "[[NSNotificationCenter defaultCenter] postNotificationName:@"TestNotification" object:self];" 4. In your module, add an observer for that notification, that will fire off an event. like so... "[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveTestNotification:) name:@"TestNotification" object:nil];" -(void)receiveTestNotification:(NSNotification*)notification { NSLog(@"[INFO] module notified "); [self fireEvent:'test' withObject:notification.userInfo]; } 5. add a listener in JS for this event. The line "module notified" will fire every time, telling you that the notification was processed and caught by the module. The event in JS will randomly not fire.
  4. Sharif AbuDarda 2016-04-26

    Hello, Please create a module only with the section that causing the issue. And provide the module in the ticket. You need to provide a test case which we can use to reproduce the issue. We need a test case and steps to reproduce the issue. Regards, Sharif.
  5. Hans Knöchel 2017-07-28

    This is no Titanium issue but an issue with the way you implement the module. The reason why it is not firing is a race-condition caused by posting the notification and sending the event asynchronously. An easy fix would be to have a protocol that is implemented by the module and triggered by the view, that's how there won't be any issues. We had similar problems in the MediaModule core-class and fixed it by waiting until the actual action was done and fire the event afterwards. It might be worth checking the source [here](https://github.com/appcelerator/titanium_mobile/blob/master/iphone/Classes/MediaModule.m).
  6. Eric Merriman 2018-08-06

    Closing as invalid. If incorrect, please reopen.

JSON Source