Multiple Implementations of CLLocationManager

I am wondering if it is difficult to implement two different SDKs that use the CLLocationManager functionality in one application.

Both SDKs control CLBeaconRegions, and both have implemented different classes with CLLocationManager instances and delegations.

Possible problems:

What if one of the SDK removes all controlled CLBeaconRegions from it CLLocationManager. Does this affect another CLLocationManager SDK?

What if both SDKs start looking for the same UUID (but with a different CLBeaconRegion identifier) โ€‹โ€‹... will both receive a delegate call?

I canโ€™t think of any other reason why this should not work, but maybe I am missing something?

+4
source share
1 answer

Have you tried using the Shared Instance? What you can do is try to manage your code with a single dispatcher instance. Thus, any change in the delegate can reflect in one class, from there you can manage your code.

Example: - .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;
}

// other delegates and stuff to control in .m

In some cases, when you use, use the intace shared interface

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

All Articles