IPhone : iOS - customize class method in a singleton

on Wednesday, April 1, 2015

I am customizing my singleton class of CLLocationManager.


I have



@property (nonatomic, strong) CLLocationManager *sManager;


and



static MyLocationManager* sMyLocationManager=nil;

+(instancetype)sharedLocationManager{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sMyLocationManager = [[self alloc] init];

});
return sMyLocationManager;

}


I could able to write my own methods as



-(void)settingUserLocationManager{
if(nil== sMyLocationManager.sManager){
sMyLocationManager.sManager = [[CLLocationManager alloc] init];
}
-(void)onStartUpdatingUserLocation{
[sMyLocationManager.sManager startUpdatingLocation];
return;
}
-(void)onStopUpdatingUserLocation{
[sMyLocationManager.sManager stopUpdatingLocation];
}


startUpdatingLocation and stopUpdatingLocation are instance methods and this how I use them, while [CLLocationManager locationServicesEnabled] is a class method. I have no idea how to use that in my singleton class.


I have tries using it as



+(BOOL)locationServicesEnabled {
return [sMyLocationManager.sManager locationServicesEnabled];
}


but not working as expected. Kindly add some ideas.


0 comments:

Post a Comment