Random thoughts & observations

From the mundane to the profound and everything in between here’s what’s rocking our world

Xcode 5 accelerometer warning for ios7

Posted: January 13, 2014
Written by: Saints At Play
Category: PhoneGap

If you're developing mobile Apps for iOS7 using PhoneGap 3+ and Xcode 5 chances are you've come across compiler warnings when publishing your app to an iOS device.

Typically these will involve the following:

  • UIAccelerometer' is deprecated: first deprecated in iOS 5.0 - UIAccelerometer has been replaced by the CoreMotion framework
  • Implicit conversion loses integer precision: 'unsigned long long' to 'int'

Publishing your App still works but how to resolve these warnings? Read on...

A handful of needles in a haystack

Now not being Objective-C developers ourselves (as most PhoneGap developers can readily identify with) digging around in various files where these errors originate can be a little daunting.

Being unfamiliar with the code and unsure of how to even begin to resolve these warnings (without introducing further issues) we resorted to every developer's last (and quite often first measure): Google.

After some time searching on variations of the same query and reading returned results on various posts from Stack Overflow and similar developer oriented websites we came across the following fixes that worked for us (warning - use at your own risk! We accept no responsibility for your decision to test/use the following. They worked for us but that might not be the case for others. We decided to share this as a courtesy with other developers who might be experiencing similar issues).

Resolving Accelerometer deprecated warnings

Assuming your App does not require motion detection then navigate to the following file in your iOS project directory: Plugins/org.apache.cordova.device-motion/CDVAcceloremeter.m and comment out the lines listed below:

  • 57
  • 58
  • 61
  • 64
  • 76
  • 78

Re-publish your App and you should see that the previous warning: 'UIAccelerometer' is deprecated: first deprecated in iOS 5.0 - UIAccelerometer has been replaced by the CoreMotion framework is no longer reported in the list of warnings that the compiler returns.

One down, one to go...

Resolving Implicit conversion loses integer precision: 'unsigned long long' to 'int' warnings

Navigate to the following file in your iOS project directory: Plugins/org.apache.cordova.file/CDVFile.m and change the following code snippet on line 1273:

  unsigned long long newPos = [self truncateFile:appFile atPosition:pos];

To the following:

  int newPos = (int) [self truncateFile:appFile atPosition:pos];

Thanks to one post we came across on Stack Overflow the solution appears to be explicitly casting the value for this variable to an integer. Once we implemented this (not really expecting that much to happen - this is development after all, sometimes when you've been debugging for what feels like hours hope tends to take something of a hit) we found the last of our compiler warnings had disappeared and we were able to publish our App without any further issues.

As we've stated above these fixes might not work for everyone and if you do choose to use them do so at your own risk. We found they worked for what we needed and if they can help others then that's great - which is one of the main reasons why we love the web!

« Return to Posts

Comments

Gravatar
Dan

January 30, 2014

Thank you so much guys.

Posting comments after three months has been disabled.