[AC-2869] Calling removeEventListener on Geolocation event prevents addEventListener from working
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-03-08T22:42:00.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | eventlistener, geolocation |
Reporter | Martyn Joyce |
Assignee | Daniel Sefton |
Created | 2012-05-30T04:45:46.000+0000 |
Updated | 2016-03-08T07:47:49.000+0000 |
Description
If Ti.Geolocation.removeEventListener() is called when Ti.Geolocation.addEventListener() has NOT been added the system remembers and subsequently removes the listener once you add it, even if this is at a later time.
In the following example use these click orders:
This works Correctly:
- Add Event Listener
- Remove Event Listener
- Add Event listener
This does not work correctly
- Remove Event Listener
- Add Event Listener
however clicking Add event Listener again will work.
This also stacks. Clicking Remove Event Listener 5 times, means that Add Event Listener needs to be clicked 5 times before it starts delivering events.
The example shows calls for 'heading' but I believe this also occurs for location.
Ti.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_GPS;
Ti.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_HIGH;
Ti.Geolocation.purpose = 'Determine Position';
Ti.Geolocation.headingFilter = 5;
Ti.Geolocation.showCalibration = true;
Ti.Geolocation.distanceFilter = 10;
var win1 = Titanium.UI.createWindow({
backgroundColor:'#fff'
});
var btnAdd = Ti.UI.createButton({
top: 100,
title: 'Add Event Listener',
})
btnAdd.addEventListener('click', addGeoEvent);
var btnRemove = Ti.UI.createButton({
top: 200,
title: 'Remove Event Listener',
})
btnRemove.addEventListener('click', removeGeoEvent);
win1.add(btnAdd);
win1.add(btnRemove);
function addGeoEvent(){
Ti.API.info('adding listener');
Ti.Geolocation.addEventListener('heading', headingCallback);
}
function removeGeoEvent(){
Ti.API.info('removing listener');
Ti.Geolocation.removeEventListener('heading', headingCallback);
}
function headingCallback(e){
Ti.API.info('heading = ' + e.heading.magneticHeading);
}
win1.open();
Hi Martyn, What platform you're referring to Android or iOS? I tested the above test case on iPhone and its working fine.
Hi Nikhil, this is on iOS version 5.1 however, apologies, my use-case above seems to be slightly off: This DOES work in the first instance 1 - Remove Event Listener 2 - Add Event Listener But if you continue it stops working i.e. 1 - Remove Event Listener 2 - Add Event Listener 3 - Remove Event Listener 4 - Remove Event Listener 5 - Remove Event Listener 6 - Add Event Listener - no events are generated here 7 - Add Event Listener - no events are generated here 8 - Add Event Listener - events are now generated In practice this occurs because we 'remove' as a safety measure to make sure the gps is turned off, however using variables to keep track of the status has solved my problem temporarily. thanks
Hi, With a test the the latest TISDK 3.0.2 or CI, this issue was not reproducible. Can you please test our latest SDK? If the problem exists, you can provide us some log files. Thanks,