[TIMOB-24916] [iOS] Application crashes when "Ti.Geolocation.getLastGeolocation" is called before a geoLocation is set
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2017-07-11T23:46:19.000+0000 |
Affected Version/s | Release 6.2.0 |
Fix Version/s | Release 6.2.0 |
Components | iOS |
Labels | n/a |
Reporter | Samir Mohammed |
Assignee | Hans Knöchel |
Created | 2017-06-30T17:15:30.000+0000 |
Updated | 2017-07-20T21:09:22.000+0000 |
Description
When
Ti.Geolocation.getLastGeolocation
is called before a geoLocaiton has been set the application crashes and the log displays the following error.
[ERROR] : Script Error {
[ERROR] : column = 967;
[ERROR] : line = 1;
[ERROR] : message = "*** +[NSJSONSerialization dataWithJSONObject:options:error:]: value parameter is nil";
[ERROR] : sourceURL = "file:///var/containers/Bundle/Application/E14637A6-6008-4878-868B-BE5E7555A790/T8.app/app.js";
[ERROR] : stack = "[native code]\nfile:///var/containers/Bundle/Application/E14637A6-6008-4878-868B-BE5E7555A790/T8.app/app.js:1:967";
[ERROR] : }
This is different to Android and 6.1.1.GA where the log instead showed:
[DEBUG] : Location undefined
*Test Steps*
1. Create a new titanium project using SDK version: 6.2.0.v20170630062735
2. Add the following code to the app.js
Titanium.UI.setBackgroundColor('#000');
var win1 = Titanium.UI.createWindow({
title:'Geo Test',
backgroundColor:'#fff'
});
var label1 = Titanium.UI.createLabel({
color:'#999',
text:'GEO TEST',
font:{fontSize:20,fontFamily:'Helvetica Neue'},
textAlign:'center',
width:'auto',top:280
});
win1.add(label1);
var btn1 = Ti.UI.createButton({title:'Last analytics',top:10,left:10,right:10,height:80});
btn1.addEventListener('click',function(){Ti.API.debug('Event?'); label1.text = 'Event: ' + Ti.Analytics.lastEvent;});
win1.add(btn1);
var btn2 = Ti.UI.createButton({title:'Start Geo',top:100,left:10,right:10,height:80});
btn2.addEventListener('click',function(){Ti.API.debug('Geo Started!');
Titanium.Geolocation.addEventListener('location',function(e)
{
if (e.error)
{
label1.text = 'error: ' + e.error;
return;
}
});
});
win1.add(btn2);
var btn3 = Ti.UI.createButton({title:'Get Geo',top:190,left:10,right:10,height:80});
btn3.addEventListener('click',function(){Ti.API.debug("Location " + Ti.Geolocation.getLastGeolocation());
});
win1.add(btn3);
win1.open();
3. Run the application on an iOS device
4. Once the application has launched press the Get Geo
button
*Expected result*
Application should not crash and the log should display the following message
[DEBUG] : Location undefined
*Actual result*
Application crashes and the above error message is displayed
NOTE:* This could also be why some of the newer Jenkins builds have been failing as the test case for this failed in a few builds.
PR: https://github.com/appcelerator/titanium_mobile/pull/9186
Verified fix in SDK Version: 6.2.0.v20170719160617 . Test and other information can be found at: https://github.com/appcelerator/titanium_mobile/pull/9186