标签: cllocationmanager

位置服务在iOS 8中不起作用

我在iOS 7上运行良好的应用程序无法与iOS 8 SDK一起使用.

CLLocationManager没有返回位置,我也没有在设置 - > 位置服务下看到我的应用程序.我在这个问题上进行了谷歌搜索,但没有出现任何问题.可能有什么不对?

location objective-c cllocationmanager ios8

606
推荐指数
15
解决办法
27万
查看次数

获取用户的当前位置/坐标

如何存储用户的当前位置并在地图上显示位置?

我能够在地图上显示预定义的坐标,我只是不知道如何从设备接收信息.

另外我知道我必须在Plist中添加一些项目.我怎样才能做到这一点?

iphone location cllocationmanager ios swift

179
推荐指数
12
解决办法
23万
查看次数

168
推荐指数
6
解决办法
20万
查看次数

终止/暂停时重要更改位置API的行为?

这是CLLocationManager文档中描述使用startMonitoringSignificantLocationChanges的应用程序行为的部分:

如果您启动此服务并且您的应用程序随后终止,则系统会在新事件到达时自动将应用程序重新启动到后台.在这种情况下,传递给应用程序的选项字典:didFinishLaunchingWithOptions:应用程序委托的方法包含密钥UIApplicationLaunchOptionsLocationKey,以指示您的应用程序是由于位置事件而启动的.重新启动后,您仍必须配置位置管理器对象并调用此方法以继续接收位置事件.重新启动位置服务时,会立即将当前事件传递给您的代理.此外,即使在启动位置服务之前,也会使用最新的位置对象填充位置管理器对象的位置属性.

所以我的理解是,如果你的应用程序终止(并假设你没有从applicationWillTerminate调用stopMonitoringSignificantLocationChanges),你将会被应用程序唤醒UIApplicationLaunchOptionsLocationKey参数:didFinishLaunchingWithOptions.此时,您将创建CLLocationManager,调用startMonitoringSignificantLocationChanges并在有限时间内执行后台位置处理.这一点我很好.

前一段只谈到应用程序终止时会发生什么,它不会建议您在应用程序暂停时执行的操作.didFinishLaunchingWithOptions的文档说:

该应用程序在后台跟踪位置更新,已被清除,现在已重新启动.在这种情况下,字典包含一个键,表示由于新的位置事件导致应用程序重新启动.

建议您在终止后启动应用程序(因为位置更改)时才会收到此呼叫.

但是," 位置感知规划指南"中关于重大变更服务的段落如下:

如果您使此服务保持运行并且您的应用程序随后被暂停或终止,则服务会在新位置数据到达时自动唤醒您的应用程序.在唤醒时,您的应用程序将被置于后台并给予少量时间来处理位置数据.由于您的应用程序位于后台,因此应该执行最少的工作并避免任何可能阻止其在分配的时间到期之前返回的任务(例如查询网络).如果没有,您的申请可能会被终止.

这表明如果您的应用已被暂停,您会被位置数据唤醒,但未提及您是如何被唤醒的:

在写这篇文章的过程中,我想我可能刚刚回答了我自己的问题,但是如果有更多知识渊博的人对我的理解得到证实,那就太棒了.

core-location uiapplicationdelegate cllocationmanager ios

109
推荐指数
2
解决办法
3万
查看次数

didFailWithError:错误域= kCLErrorDomain代码= 0"无法完成操作.(kCLErrorDomain error 0.)"

我想获取当前位置,但我得到一个错误.

这是我的视图控制器的片段.

- (void)viewDidLoad {
    self.locationManager = [[CLLocationManager alloc] init];
    [locationManager setDelegate:self];
    [locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
    [locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager 
     didUpdateLocations:(NSArray<CLLocation *> *)locations {
    // I would get the latest location here
    // but this method never gets called
}
- (void)locationManager:(CLLocationManager *)manager 
       didFailWithError:(NSError *)error {
    NSLog(@"didFailWithError: %@", error);
}
Run Code Online (Sandbox Code Playgroud)

我期待委托方法locationManager:didUpdateLocations:被调用,但只是locationManager:didFailWithError:被调用,并打印出来:

didFailWithError: Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)" 
Run Code Online (Sandbox Code Playgroud)

iphone core-location cllocationmanager cllocation ios

79
推荐指数
9
解决办法
8万
查看次数

XCode/iOS模拟器:手动触发重要的位置更改

有没有办法手动告诉设备发送重要的位置变更通知,该通知会唤醒为此通知注册的任何应用程序?这仅用于测试,我意识到这个私有API调用在提交到应用商店时会被拒绝.

iphone core-location cllocationmanager ios

75
推荐指数
2
解决办法
2万
查看次数

iOS:应用程序在安装应用程序时不会询问用户的权限.每次都得到kCLAuthorizationStatusNotDetermined - Objective-c&Swift

我正在尝试在我的iOS应用中获取用户位置.我首先在我的项目中包含了重置框架.然后在按钮上单击我调用核心位置api,如下所示.当我尝试在设备中安装它时,核心位置永远不会询问用户权限.当我尝试在按钮单击时获取位置时,我将获得kCLAuthorizationStatusNotDetermined作为authorisationStatus.请帮帮我.我不知道发生了什么.

- (IBAction)fetchLessAccurateLocation:(id)sender {
    [self.txtLocation setText:@""];

    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
    locationManager.distanceFilter = 1000;

    if ([self shouldFetchUserLocation]) {
        [locationManager startUpdatingLocation];
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的shouldFetchUserLocation方法:

-(BOOL)shouldFetchUserLocation{

    BOOL shouldFetchLocation= NO;

    if ([CLLocationManager locationServicesEnabled]) {
        switch ([CLLocationManager authorizationStatus]) {
            case kCLAuthorizationStatusAuthorized:
                shouldFetchLocation= YES;
                break;
            case kCLAuthorizationStatusDenied:
            {
                UIAlertView *alert= [[UIAlertView alloc]initWithTitle:@"Error" message:@"App level settings has been denied" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
                [alert show];
                alert= nil;
            }
                break;
            case kCLAuthorizationStatusNotDetermined:
            {
                UIAlertView *alert= [[UIAlertView alloc]initWithTitle:@"Error" message:@"The user is yet …
Run Code Online (Sandbox Code Playgroud)

gps core-location cllocationmanager ios

70
推荐指数
6
解决办法
9万
查看次数

为什么requestWhenInUseAuthorization不提示用户访问该位置?

在我的viewDidLoad方法中,我有

locationManager = [[CLLocationManager alloc]init]; // initializing locationManager
locationManager.delegate = self; // we set the delegate of locationManager to self.
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];


if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
    [locationManager requestWhenInUseAuthorization];
}
Run Code Online (Sandbox Code Playgroud)

并且调用了请求,但是没有提示用户?为什么?

xcode objective-c cllocationmanager ios8

69
推荐指数
1
解决办法
6万
查看次数

didUpdateLocations而不是didUpdateToLocation

随着iOS6的发布,Apple希望我们使用didUpdateLocations而不是didUpdateToLocation.谁能解释如何正确使用didUpdateLocations?

objective-c core-location cllocationmanager ios swift

66
推荐指数
4
解决办法
4万
查看次数

iOS9中的CLLocationManager中的allowsBackgroundLocationUpdates

CoreLocation在我的应用程序中使用Xcode7(预发布)中的框架,我注意到allowsBackgroundLocationUpdatesCLLocationManager类中有一个新添加的属性.

此属性与"功能"选项卡的"背景模式"中的位置更新之间的关系是什么.它的默认值是什么,它是否会影响在iOS9中运行的应用程序?

core-location cllocationmanager ios ios9

63
推荐指数
5
解决办法
4万
查看次数