iOS Simulator location not working - ios

I'm testing an iOS app with the simulator in xCode 5.x. The root view is a UIWebView that loads an external URL. The external page requests geolocation information, but I cannot get it to work in the simulator. The prompt appears to share location info, but the external page is unable to receive them.
I've tried setting a custom location in Debug > Location... but nothing changes.
I've tried multiple devices in the simulator, such as iPhone 3.5 and iPad.
If I load the app in an actual device, it works fine.
What am I missing?
-e

+1 to #Farhan for a helpful tip. Here's what solved my problem:
There are two places where simulator location gets set:
The Scheme (see Farhan's answer).
In the Simulator under Debug > Location
I played with the Default Location setting in the scheme and it didn't work. Mine is currently set to "None" which is unclear as to whether that means there is no location data provided or whether it defaults to the location of the host machine.
In the simulator under Debug > Location, it was also set to none. I tried using some of the presets, but it still didn't work. What eventually made it start working for me is I changed it to "Custom location" and entered the latitude and longitude of where I am located. Only then did it start working correctly.
This post has some helpful screenshots of what I'm describing.
This is a handy tool for getting latitude and longitude.
Update
The solution I described above still works, but in the project I'm currently working on it doesn't seem to retain the settings, so I have to keep re-selecting my custom location. This gets tedious, so I created a new preset location using gpx file. Turns out this is really easy. Just use this tool to generate the file and download it. Then when you edit the schema, under Default Location, choose the "Add GPX file to project..." (and select the file you downloaded). That's it. For whatever reason, this setting does seem to get remembered when I re-run the simulator.

You might need to enable it for your specific build. To do that.
In your Xcode go to Product > Scheme > Edit Scheme... 2 - In the Run projectName/ Debug
Select "Run XXXX.app / Debug" > Select "Allow Location Simulation" and select a default location.

I had the same issue - try this:
Check your Location Settings in the Simulator. Press CMD-Shift-H to exit app, go to Settings->Privacy and select 'While Using the App'. You also need to have set NSLocationWhenInUseUsageDescription key in Info.plist.

To use custom location (adding your own lat/lon coordinates), with the simulator selected, go to the options at top and select 'Features' option
Once you select the 'Customer Location' option you can enter your Lon lat details here.
Voila!

Delete app from simulator
Set coordinates from Debug/Location/Custom Location
After Hardware/Reboot simulator

If you are still faced with this issue, note that it's caused by a bug in the iOS simulator, I had already updated the custom location in the "Features > Location > Custom location..." as seen in Jim Tierney's answer but when I restarted the app, the simulator doesn't take the new custom location into consideration.
To resolve this, simply open the "Maps" app on the simulator, and make sure it's showing the custom location you selected by tapping on the location icon at the top right.
Minimize it to the background, reopen your app, stop the app and start the app, now the location would show you the expected result.

Xcode supports GPX files but it is important to note that the GPX file needs to contain waypoints. Tracepoints don't work, so make sure to only use "wpt" tags in your GPX.

I am also facing the same issue. The location package worked fine on Android, but on iOS devices, it didn't get the location information. So I solve this by changing the location from Simulator Settings.
Solution:
From Simulation Bar > Features > Location > Apple (Select this)
This solves my issue !!
Now I can get location data.

For me, the problem was that "Debug Executable" wasn't checked on the scheme I was running. Once I enabled this, everything started working normally again with the location simulation.

Related

Simulate fake location on real iOS device

I want to simulate fake location on my iPhone 5S device using specific longitude and latitude. Is there a way to do this in XCode. I tried using the simulate location feature by adding a GPX file in XCode but it's not working. Thank you in advance.
It is possible.
You only have to:
1) plug your device to the computer.
2) run an app in the real device (it is the same which application). It is only to have the menu enabled.
3) in Xcode (not in the simulator) Go to menu: Debug -> Simulate Location and select one or add a GPX file.
It will simulate the location not only for the application executed but for all of them.
I suppose that the phone must be in developer mode but if you run apps from Xcode it must be anyway.
I've tested it from Xcode 6 in an iPhone 4 iOS 7.1.2
Hope it helps
In addition to the method for setting a simulated location at runtime as mentioned in this answer, you can set/change the default simulated location for a default device/configuration prior to runtime in Xcode at:
Product (menu) > Scheme > Edit Scheme > Options (tab) > Default Location

Geolocation is not working in iOS 8 simulator

I have upgraded the geolocation plugin in cordova 3.5 to fix the issue in iOS 8 by following this post.
http://shazronatadobe.wordpress.com/2014/09/18/cordova-ios-and-ios-8/
After running the app in iOS8 simulator, I am getting the notification 'Allow "MyApp" to access your location while you use the app?' But it still shows the error locationManager::didFailWithError (null) after allowing the location service to use the app. I have tried to close the simulator and run it again and again. Also it seems that location service is active (Settings > Privacy > Location services > MyApp > While Using) by checking the settings in the simulator. By running the same app in iOS 7 simulator is working fine and able to detect the lat/lng.
FYI: I am using Xcode 6 to build the application.
Any help/suggestion will be helpful.
it sounds strange but it really works at least on my Xcode 6 Project. Make also sure to add the required Keys to your Projectname-info.plist file (e.g NSLocationWhenInUseUsageDescription -> as a Key)
Next check your scheme (Product -> Scheme -> Edit Scheme -> Allow Location Simulation)
If you are using a gpx file you can also mark it as a default location.
Now you can start your simulator by pressing the run button (play symbol). As soon as your application started you will get notified for the permission.
The final fix now is to go to iOS Simulator -> Debug -> Location and change the location by choosing one out of the list except the custom location. Wait a little and change it back to custom location if it didnt change back by itself.
It worked for me,
hope for you too
regards
Schreda
In iOS Simulator -> Debug -> Location, choose one
that will be alright,

iOS Simulator Reverts Location Setting

I am using a Custom Location under Debug --> Location --> Custom Location
While this setting does work just fine for me, the simulator frequently changes my setting from Custom Location to None. This reverting does not appear to have a pattern as I may run the same project 5 or 10 times without the setting reverting. Other times it changes the Location to None every 1 or 2 times I run the simulator.
Is there a way to lock the setting in so I do not have to fight with it?
Have you tried setting a default location? May be it is set to none.
Edit your scheme > Select "Run XXXX.app / Debug" > Select "Allow Location Simulation" and select a default location.
The accepted answer it is a solution, solved your problem, but for other developers that are facing this issue, there is also a easier solution where you don't need a GPX file or to select one of the locations provided as default:
In your Xcode go to Product > Scheme > Edit Scheme...
In the Run projectName/ Debug, go to Options and Deselect "Allow Location Simulation".. yes uncheck it!
Press OK
Run your app in the simulator
On simulator menu choose Debug > Location > Custom Location
Specify latitude/longitude coordinates
Now the simulator will keep this as default location. Actually the Allow Location Simulation on Xcode, together with the option none is the reason for "forgetting" the location you added before.
From now on, your simulator will always remember the last custom location!

iOS6 Simulator MKMapKit "Couldn't find default.styleproto in framework"

Running my app with the iOS6 simulator I am getting the following printed in the XCode console prior to viewDidLoad getting called:
Couldn't find default.styleproto in framework
Has anyone else encountered this, and if so have you found a reason why? My guess is that it has to do with the iOS6 Apple Maps, but who knows!
EDIT
I should add that I don't get this warning in the iOS 5.1 simulator.
I found a way to consistently reproduce this.
First, the culprit is a set of files in the Cache folder for your simulator. Go to your Application Support folder for the iPhone Simulator:
~/Library/Application Support/iPhone Simulator/[6.0 and above]/Library
Then look inside of your Caches/GeoServices/Resources
You'll see some .styleproto files in there. These files are only created when MapKit is first used in a simulator. It may also happen on the device, but I haven't confirmed it.
If you want to test this, make sure you have the .styleproto files, then re-launch your app, and you won't see the warning again when accessing the maps.
Remove the GeoServices cache folder, quit and restart the simulator (and your app), and there is the warning!
I solved by adjusting the MKMapView in my view controller to iPhone 5 new size, now I got no warning message.
mmm...I had de same problem...I think the problem could be the 6.0 Simulator; if I set the Deployment Target to 5.1 and run the app using the 5.1 Simulator and uncheck the Autolayout check-box, I didn't have any problem, but if I use the 6.0 Simulator when I run the app, the map doesn't appear, and the message "Couldn't find default.styleproto in framework" is printed in Xcode console...
Please set your GPS settings active otherwise this error may occur again. Also,it is advisable to set the frame for the iPhone 5 .
I just turned on my wireless on device and this warning disappear and my map comes visible.
This is old, but for anyone who comes across this thread like I did, it may also be that the option "Shows User Location" on the map view object was not checked. This was my issue and not about cache above, although I got the exact same error in console. I didn't even try the cache fix from the answer above, all I did was check that option and voila.
If your iOS simulator's GPS setting is none, you will get this waring. Just change iOS simulator's GPS setting to "Apple Stores" or other, it will gone.

GPS Simulation in iOS

I am developing an app that depends on GPS data and works only in New York City. It will display "out of range" if the user is 30 miles away from Manhattan. The problem is that I am 8 hours away from New York City and can't really test the App functionality.
In Android, you can have DDMS send your device or AVD a mock location by simply pushing the lat and long coordinates. The App will then react to the location changes. I can't seem to find a way to do that in iOS.
Does anyone know how to simulate location on iOS?
Thanks
In Xcode 4.2 with the new iOS 5 SDK it is possible to simulate locations in the simulator. Launch your app in the simulator, click the Debug menu option go to Location and then click Custom Location…. The simulator should then allow you to enter longitude and latitude.
FakeGPSUtility works fine for iOS7, can say nothing nothing about iOS8. Can be installed either manually or from CocoaPods.
Manual installation:
Drag the FakeGPSUtility folder into your Xcode project;
Define 'DEBUG' in target build configuration;
Add MapKit and CoreLocation frameworks into your target.
The answer is a bit outdated so NOW you can easily simulate a location with Xcode like this:
Just run your project and press the arrow. If a location is active, it turns blue.
There are some preset locations and the last option is Add GPX File which could be any location you want. Just create one like this: New -> File -> GPX File

Resources