Why do you want to create an extra method? You could minimize the risk of errors by using already available ones: NSLog(@"Location services enabled: %d",[CLLocationManager locationServicesEnabled]);
NSLog not printing out BOOL result to console [closed]
-
21-09-2022 - |
質問
I have a location app that already successfully asks the user to enable location services, and then can show them their coordinates on a button press as well. So I decided to play around with everything that is available in the CLLocationManager reference provided by xcode.
I decided to setup a bool method called "locationServicesEnabled". It returns a value of YES(1) or NO(0). I declared the method and then went to implement it. I am trying to have NSLog print the bool result out to the console when you open the app.
Here is how I declared the BOOL method in my ViewController.m file:
@interface ViewController () <CLLocationManagerDelegate>
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;
+ (BOOL)locationServicesEnabled;
@end
And here is how I implemented the BOOL method in ViewController.m:
+ (BOOL)locationServicesEnabled{
[self locationServicesEnabled];
NSLog(@"%hhd", self.locationServicesEnabled);
return 0;
}
解決
他のヒント
I think your issue might be the fact that you are calling your function inside its self:
+ (BOOL)locationServicesEnabled
{
[self locationServicesEnabled]; <- should this be here
NSLog(@"%hhd", self.locationServicesEnabled);
return 0;
}