Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28275] iOS: RemovingEventListener in Location event will freeze App

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2021-05-18T18:27:27.000+0000
Affected Version/sn/a
Fix Version/sRelease 10.0.0, Release 9.3.3
ComponentsiOS
Labelsgeolocation, iOS
ReporterMichael Gangolf
AssigneeVijay Singh
Created2020-11-20T12:57:43.000+0000
Updated2021-05-18T18:27:31.000+0000

Description

When removing the location event inside the event itself the app will freeze:
var win = Ti.UI.createWindow({
	backgroundColor: '#fff'
});

function geoL(e) {
	Ti.Geolocation.removeEventListener('location', geoL);
	alert("after remove");
}
var btn = Ti.UI.createButton({
	title: 'Test'
});
btn.addEventListener('click', () => {
	Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE, event => {
		if (!event.success) {
			alert('No permissions');
			return;
		}
		Ti.Geolocation.addEventListener('location', geoL);
	});
});
win.add(btn);
win.open();
Tested with 8.3.1.GA and 9.2.2.GA It looks like a threading issue e.g. in startStopLocationManagerIfNeeded. A workaround would be
function geoL(e) {
    setTimeout(() => {
        Ti.Geolocation.removeEventListener('location', geoL);
    }, 2000);
	alert("after remove");
}
or removing it from a different event e.g. a button click.

Comments

  1. Vijay Singh 2021-03-11

    https://github.com/appcelerator/titanium_mobile/pull/12542
  2. Satyam Sekhri 2021-03-19

    FR Passed Waiting for Jenkins build
  3. Christopher Williams 2021-03-23

    merged to master, 10_0_X and 9_3_X branches.

JSON Source