7

This is more of an informational post: I've spent the past few days struggling with a non-functional geolocation app on the latest iOS 8 Beta.

At first I wasn't sure if it was isolated to iOS 8, or if it was an issue of device vs simulator, but after re-downloaded XCode 6 Beta 2 (my first download had a broken simulator for some reason), I confirmed that indeed, iOS 8 Beta 2 simulator did not seem to like my attempts at grabbing a geolocation.

At first the call didn't seem to work at all; then I made a change from including phonegap.js to including cordova.js and finally made some progress. The documentation is awful on this, as following guides in the official docs seems to lead one to believe they're interchangeable. I would suggest those with issues check that first.

Rather than running the navigator.geolocation.getCurrentPosition(....) callback functions as expected, it would instead hang and not do anything at all. Sometimes navigating away from the page and back to it would force the error callback, but it was very inconsistent. After setting a { timeout: 5000 } option, it seemed to keep timing out every call. There were no errors to the console, no errors in XCode, nothing. The success function just would not run, period, and neither would the error callback if I didn't explicitly timeout after X seconds. This is an error isolated to the iOS 8 Beta, so nothing of concern to most (yet), but I felt I should post this in case someone ran into it. I'll also be posting on the Apple Dev Center.

Ruben Martinez Jr.
  • 3,199
  • 5
  • 42
  • 76
  • I'm running into the same problem. My error function is set to retrieve the location via IP address, so using a timeout still *sorta* works. Would like this fixed, however. You should file a bug report. – Charlie Aug 08 '14 at 18:26

1 Answers1

16

It's a known issue and is fixed here:

https://github.com/apache/cordova-plugin-geolocation/commit/4102a332b0c6b0c3513370a4c030a32e46a51e10#commitcomment-7791523

Just tested it in iOS8, it works.

Run the following command in platforms/ios folder of your phonegap project:

cordova plugin rm org.apache.cordova.geolocation
cordova plugin add https://github.com/apache/cordova-plugin-geolocation.git   

For some reason it removes the CDVLocation.m from the compilation list, you need to revert that.

The entries In XXX.xcodeproj/project.pbxproj:

979B00CA27D6412CB8C6CF74 /* CDVLocation.m in Sources / = {isa = PBXBuildFile; fileRef = E3B4F7C4AF8242A09E9BF8C1 / CDVLocation.m */; };
979B00CA27D6412CB8C6CF74 /* CDVLocation.m in Sources */,

Without these 2 lines, the plugin is not available to use in the app.

If you have that file in source control just revert the deletions related to CDVLocation.m in XXX.xcodeproj/project.pbxproj.

If not try add CDVLocation.m to the Compile Sources step in the Build Phases in the project settings.

onlyurei
  • 439
  • 5
  • 12
  • 1
    I haven't tested this myself, but going to go ahead and accept this answer since it corroborates the fix I just read about. Thanks for the update! – Ruben Martinez Jr. Sep 19 '14 at 01:26
  • Just switching the plugin url in my hook works. Nothing required like manipulating Xcode project. – Saran Sep 23 '14 at 12:44
  • 2
    Yup, had to add CDVLocation.m to my Build Phases. Thanks @onlyurei – cranberry Sep 23 '14 at 16:27
  • 1
    i just corroborate that if you add add CDVLocation.m to "Build Phases" -> "Compile Sources" will work for latest iOS 8 (official release and not BETA nor RC) – d1jhoni1b Sep 30 '14 at 05:55
  • 1
    Just gave this a shot and it works. added in as a plugin through command line. – gregdevs Oct 03 '14 at 21:58
  • When I try this fix with phonegap 3.6.3 on xcode 6 I get an error : `-[CDVLocation startLocation:] in CDVLocation.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)` I already had this kind of error where I had to add a library in build phase but can't find any Location library in the list – Miles M. Oct 15 '14 at 22:51
  • @Saran "Just switching the plugin url in my hook works", how did you do this? Im using PG build and I was thinking that maybe this could be the answer to my problem, my geolocation plugin is working but http://i.stack.imgur.com/bDIgF.png dialog is not showing up. – decodingpanda Nov 03 '14 at 07:23
  • @zynder About hooks: http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/ I changed org.. to git url in it. – Saran Nov 03 '14 at 09:17
  • @Saran are you using PG build too? is this http://i.stack.imgur.com/bDIgF.png dialog appears to you when GPS is off? – decodingpanda Nov 04 '14 at 01:58
  • Thank you so much for this answer - I spent many hours trying to figure out what was going on before finding this. – kris Oct 17 '15 at 06:27