CLLocationManager的多个实现

时间:2014-09-18 14:27:52

标签: ios cllocationmanager ibeacon

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

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

可能出现的问题:

如果其中一个SDK从其CLLocationManager中删除所有受监视的CLBeaconRegions,该怎么办?这是否会影响其他SDK的CLLocationManager?

如果两个SDK都开始寻找相同的UUID(但具有不同的CLBeaconRegion标识符),那么两者都会获得委托调用吗?

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

1 个答案:

答案 0 :(得分:2)

您是否尝试过使用共享实例? 您可以做的是尝试使用相同的位置管理器实例管理您的代码。 因此,委托中的任何更改都可能反映在单个类中,您可以管理代码。

示例: - .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

中管理的其他delgates和东西

您使用时的某些位置使用共享插入

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