Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-24916

[iOS] Application crashes when "Ti.Geolocation.getLastGeolocation" is called before a geoLocation is set

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: Release 6.2.0
    • Fix Version/s: Release 6.2.0
    • Component/s: iOS
    • Labels:
      None
    • Environment:

      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.

        Attachments

          Activity

            People

            • Assignee:
              hknoechel Hans Knöchel
              Reporter:
              smohammed Samir Mohammed
              Reviewer:
              Vijay Singh
              Tester:
              Samir Mohammed
            • Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-10855
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Source Code