[MOD-2249] Appcelerator module events stop firing
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2017-07-28T19:26:48.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | n/a |
Reporter | derick alt |
Assignee | Unknown |
Created | 2016-04-18T18:49:00.000+0000 |
Updated | 2018-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
I was able to work around this issue for the time being by moving all events to my custom view, using [[self proxy] fireevent...]
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.
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.
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.
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).Closing as invalid. If incorrect, please reopen.