iOS 6 CoreLocation does not work

醉酒当歌 提交于 2019-12-03 20:16:25

In iOS 6 Apple has made breaking changes to Core Location by implementing the AutoPause API. The AutoPause API pauses the location updates when an application goes into the background and applies to a couple of criteria (i.e. user not moving, no location fix, user discontinues activity). To accurately handle pause events Apple requests to help better predicting whether or not to pause location updates setting an activity type (i.e. navigation, fitness, other). The AutoPause API is enabled by default when an application is compiled against iOS 6.

The easy fix is to disable the AutoPause API for now by always setting 'pausesLocationUpdatesAutomatically' to NO. Location updates will be send even when the app goes in the background, like it used to work in < iOS 6.

More details here:

http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation delegate doesnt exist in ios 6 anymore.

Instead use

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray*)locations

Check Apple documentation for startUpdateLocation

This code (and the pausesLocationUpdatesAutomatically) would compile only in XCode 4.5 (where the base SDK is 6).

If you want to target iOS versions prior to 6.0 then use this macro

#define IOS_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

and wherever you are creating the CLLocationManager object

if(IOS_VERSION_GREATER_THAN_OR_EQUAL_TO (@"6.0"))
{
    locationManagerObj.pausesLocationUpdatesAutomatically = NO;
}

The locationManager delegate should work in all version when compiled from Xcode 4.5

Do you have any message from delegate method ?

If no message, check interface description of you class.

@interface ... <... CLLocationManagerDelegate ...>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!