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

iOS: Core Motion crashes when the user moves

    Details

    • Type: Bug
    • Status: Closed
    • Priority: High
    • Resolution: Duplicate
    • Affects Version/s: Release 5.0.1, Release 5.0.2, Release 5.0.0
    • Fix Version/s: Release 5.2.0
    • Component/s: iOS
    • Labels:
    • Environment:

      iOS 9.1
      Xcode 7.1
      Appcelerator Studio, build: 4.3.1.201509302304

    • Sprint:
      2015 Sprint 23 SDK

      Description

      Issue Description

      Core motion is crashing using iOS 9.1 on device when the user start to move or walk

      Steps to reproduce

      1- create a sample app alloy project
      2. paste the next code:

      app/views/index.xml

      <Alloy>
          <Window backgroundColor="white" layout="vertical">
              <Label>Pitch:</Label>
              <ProgressBar id="pitch" />
              <Label>Roll:</Label>
              <ProgressBar id="roll" />
              <Label>Yaw:</Label>
              <ProgressBar id="yaw" />
          </Window>
      </Alloy>
      

      app/styles/index.tss

      "ProgressBar" : {
          "top" : 10,
          "width" : 200,
          "min" : 0,
          "max" : 3.1415927
      },
      "Label" : {
          "font" : {
              textStyle: Ti.UI.TEXT_STYLE_SUBHEADLINE
          },
          "top" : 50,
          "left" : 10
      } 
      

      app/controllers/index.js

      var accelX = accelY = accelZ = 0;
      var lastX = lastY = lastZ = 0;
      var ACCEL_THRESHOLD = 2;
      var SHAKE_THRESHOLD = 5;
      var CoreMotion = require('ti.coremotion');
      if (CoreMotion.isDeviceMotionAvailable()) {
          CoreMotion.setDeviceMotionUpdateInterval(500);
          var frames = CoreMotion.availableAttitudeReferenceFrames();
          var ref_frame = CoreMotion.ATTITUDE_REFERENCE_FRAME_X_TRUE_NORTH_Z_VERTICAL;
          if (frames & ref_frame) {
              // Use the True North Frame if available
              Ti.API.debug('REFERENCE FRAME: True North');
              CoreMotion.startDeviceMotionUpdatesUsingReferenceFrame(
                  {referenceFrame: ref_frame},
                  updateMotionData    
              );
          }
          else if (ref_frame = CoreMotion.getAttitudeReferenceFrame()) {
              // Use the default frame if it exists
              Ti.API.debug('REFERENCE FRAME: Default ' + ref_frame);
              CoreMotion.startDeviceMotionUpdatesUsingReferenceFrame(
                  {referenceFrame: ref_frame},
                  updateMotionData    
              );        
          } else {
              // Do not use a reference frame
              Ti.API.debug('REFERENCE FRAME: None');
              CoreMotion.startDeviceMotionUpdates(updateMotionData);
          }
      }
      function updateMotionData (e) {
          
          if (e.success) {     
              var data = e.userAcceleration;
              if (Math.abs(lastX - data.x) > ACCEL_THRESHOLD) {
                  accelX++;
              }
              if (Math.abs(lastY - data.y) > ACCEL_THRESHOLD) {
                  accelY++;
              }
              if (Math.abs(lastZ - data.z) > ACCEL_THRESHOLD) {
                  accelZ++;
              }
              analyzeResults();
              lastX = data.x;
              lastY = data.y;
              lastZ = data.z;
              
              data = e.attitude;
              $.pitch.message = data.pitch;
              $.pitch.value = Math.abs(data.pitch);
              $.roll.message = data.roll;
              $.roll.value = Math.abs(data.roll);
              $.yaw.message = data.yaw;
              $.yaw.value = Math.abs(data.yaw);
          } else {
              if (e.error) Ti.API.error(e.error);
          }
      }
      function analyzeResults(){
          if (accelX > SHAKE_THRESHOLD || accelY > SHAKE_THRESHOLD || accelZ > SHAKE_THRESHOLD) {
              var err = SHAKE_THRESHOLD * 0.5;
              if (accelX > SHAKE_THRESHOLD && (accelY < err && accelZ < err)){
                  alert("Quit shaking me back and forth!");
              }
              else if (accelY > SHAKE_THRESHOLD && (accelX < err && accelZ < err)){
                  alert("Quit shaking me up and down!");
              }
              else if (accelZ > SHAKE_THRESHOLD && (accelX < err && accelY < err)){
                  alert("Why are you shaking me like that?!");
              }
              else {
                  alert("Quit shaking me!");
              }        
              accelX = accelY = accelZ = 0;
          }
      }
      $.pitch.show();
      $.roll.show();
      $.yaw.show();
      $.index.open();
      

      3- Add the Core Motion Module
      4- Build and run on device
      5.- Move and Walk

      The app will close unexpectedly

      Expected Behavior

      The app should keep working

      **Additional notes:
      Attached Xcode crash log image.
      This is also happening on the movies sample app

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                hknoechel Hans Knöchel
                Reporter:
                rramirez Ricardo Ramirez
                Reviewer:
                Chee Kiat Ng (Inactive)
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

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

                    Git Source Code