- Home /
iOS 8 location services not working
I'm using an iPhone 5 / iPad 4th gen both with iOS 8 GM, Xcode 6.0 and Unity 4.6.0b17 I've been having trouble with location services on the devices... very frustrating as I previously had this working.
To rule out any other issues, I crated an empty project with a scene containing a cube. I attached the following script from unity script reference: http://docs.unity3d.com/ScriptReference/LocationService.Start.html And installed the application on my device. Additionally, I tried a second new project using U3DXT examples scene unmodified and installed it on my device also.
Firstly I'm not prompted to enable location services in either application, and in the unity script reference application, a location of 0,0,0,0 is returned.
In the device Settings > Privacy > Location Services, my applications are listed but no selection appears in the tableview. If I select 'always' in the setting screen and return to either application the location still is not determined. When I recheck the Settings > Privacy > Location Services after relaunching the application, the 'always' selection seems to have reset to having no selection.
An older build I created a while back seems to be working correctly.
Does this seem like a iOS 8 GM issue? Is it possible I've inadvertently done something silly to a setting in Unity?
Any thoughts or suggestions would be helpful.
Answer by pavel_stupka · Sep 23, 2014 at 11:21 AM
Hi there, first of all I'm using Unity 4.5.4f1 but the solution should be the same. After you build an Xcode project from Unity, open it it Xcode and then:
* Find -> Find in Project
* Search for: startUpdatingLocation
* It should find 2 source files: "iPhone_Sensors.h" and "iPhone_Sensors.mm"
* Open "iPhone_Sensors.h" and add:
#define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
* Open iPhone_Sensors.mm and before the line:
[locationManager startUpdatingLocation];
Add the following code:
if(IS_OS_8_OR_LATER) {
[locationManager requestAlwaysAuthorization];
}
* At the end add "NSLocationAlwaysUsageDescription" to your Info.plist as a string with your customized message.
See more at: http://9to5mac.com/2014/06/04/apple-improves-location-services-in-ios-8-with-when-in-use-mode-visit-monitoring/
Hi, thanks for the reply. This solution works, in part, beautifully. Once I have set the Privacy > Location Services > > Always... I am able to successfully pull the location from the device. Perfect!
However, I'm not asked to "Allow to access your location..." When I try to access the location for the first time. I've deleted the application and rebuilt using Xcode as I know that can be an issue. However, the request is still never made. I currently need to go into the location services settings and specifically set the app to Always.
Any other thoughts on what may be going wrong?
Thank you very much for you time with this, it is greatly appreciated.
Oh, this is even more strange. I managed to get your solution to work perfectly when the application launches into my own custom scene... the request for authorisation pops up straight away. It just didn't work from when launching into the example scenes in U3DXT in the same Unity project.
Thank you for your help pavel_stupka.
Hey thanks for posting this answer! I've been banging my head against the wall thinking I was doing something wrong. You RoCk!
Thanks for posting I was running into this exact problem on iOS8 running Unity 4.5.3. I'll give your solution a test and hopefully Unity officially fixes it soon.
Will there be any Unity patch to fix this? I mean the Xcode project might be overwritten, and adjusting the generated code every time seems to be very tedious. Using 4.5.5 currently.
Answer by fschneider · Dec 03, 2014 at 10:23 AM
It seems 4.5.5p1 is such a patch, see http://unity3d.com/unity/qa/patch-releases
I recommend to install at least patch 2 however as patch 1 contains a new bug.