gpt4 book ai didi

ios - CLLocationManager 的多种实现

转载 作者:可可西里 更新时间:2023-11-01 05:53:31 27 4
gpt4 key购买 nike

我想知道在一个应用中实现两个使用 CLLocationManager 功能的不同 SDK 是否有问题。

两个 SDK 都在监控 CLBeaconRegions,并且都使用 CLLocationManager 实例和委托(delegate)实现实现了不同的类。

可能出现的问题:

如果其中一个 SDK 从它的 CLLocationManager 中删除所有受监控的 CLBeaconRegions 会怎样。这是否也会影响其他 SDK 的 CLLocationManager?

如果两个 SDK 开始寻找相同的 UUID(但具有不同的 CLBeaconRegion 标识符)怎么办...是否都收到委托(delegate)调用?

我想不出这不起作用的任何其他原因,但也许我遗漏了什么?

最佳答案

您尝试过共享实例吗?您可以做的是尝试使用相同的位置管理器实例来管理您的代码。因此,委托(delegate)中的任何更改都可能反射(reflect)在单个类中,您可以从那里管理您的代码。

例子:-.h

#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@interface LocationManager : NSObject <CLLocationManagerDelegate>
@property (nonatomic,strong) CLLocationManager *objLocationManager;
@property (nonatomic,assign) CLLocationCoordinate2D currentcoordinate;
+ (LocationManager *) SharedInstance;
+ (CLLocation *) currentLocation;
@end

.m

#define currentCordinates [LocationManager SharedInstance].currentcoordinate
#define currentLocationmanger [LocationManager SharedInstance].objLocationManager
// Shared Manager
static LocationManager *SharedInstance = nil;

+ (LocationManager *) SharedInstance
{
@synchronized(self)
{
if (SharedInstance == nil)
{
SharedInstance = [[super allocWithZone:NULL] init];
currentLocationmanger = [[CLLocationManager alloc]init];
currentLocationmanger.delegate = [LocationManager SharedInstance];


/* Pinpoint our location with the following accuracy:
*
* kCLLocationAccuracyBestForNavigation highest + sensor data
* kCLLocationAccuracyBest highest
* kCLLocationAccuracyNearestTenMeters 10 meters
* kCLLocationAccuracyHundredMeters 100 meters
* kCLLocationAccuracyKilometer 1000 meters
* kCLLocationAccuracyThreeKilometers 3000 meters
*/
currentLocationmanger.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;

/* Notify changes when device has moved x meters.
* Default value is kCLDistanceFilterNone: all movements are reported.
*/
currentLocationmanger.distanceFilter = 2.0f;

/* Notify heading changes when heading is > 5.
* Default value is kCLHeadingFilterNone: all movements are reported.
*/
currentLocationmanger.headingFilter = 5;

[LocationManager SharedInstance].geocoder = [[CLGeocoder alloc] init];

[[LocationManager SharedInstance].objLocationManager startUpdatingLocation];

// update location
if ([CLLocationManager locationServicesEnabled]){
[currentLocationmanger startMonitoringSignificantLocationChanges];
}
}
}
return SharedInstance;
}

//.m 中要管理的其他委托(delegate)和内容

有些地方在你使用的时候是与共享实例一起使用

//region.span = span;
region.center = [LocationManager SharedInstance].currentcoordinate;

关于ios - CLLocationManager 的多种实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25915438/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com