Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////////////////////////
- // by Roman Shelep
- ////////////////////////////////////////////////////////////////////////////////
- #import "YMSetupActionLocation.h"
- #import "CCLocationService.h"
- #import "NSObject+FactoryHooks.h"
- #import "NSError+CCTableFormManager.h"
- NSInteger YMLocationServicesDisabledInSettingsErrorCode = 1234;
- @implementation YMSetupActionLocation
- {
- }
- - (void)typhoonDidInject
- {
- [self setText:@"Allow" forState:YMSetupActionStateToDo];
- [self setText:@"Location Services" forState:YMSetupActionStateBlocked];
- [self setText:@"Location Services" forState:YMSetupActionStateComplete];
- @weakify(self);
- self.locationService.didChangeAuthStatusBlock = ^(CLAuthorizationStatus status) {
- @strongify(self);
- [self updateEnrollStatus];
- };
- [self updateEnrollStatus];
- }
- - (void)updateEnrollStatus
- {
- self.state = [self.locationService isLocationServiceEnabled] ? YMSetupActionStateComplete : YMSetupActionStateToDo;
- }
- - (void)enrollWithView:(id<CCGeneralViewInput>)view completion:(YMSetupCompletion)completion
- {
- CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
- if (![CLLocationManager locationServicesEnabled] || status == kCLAuthorizationStatusDenied) {
- NSError *error = [NSError errorWithCode:YMLocationServicesDisabledInSettingsErrorCode name:nil localizedDescription:nil];
- completion(NO, error);
- } else {
- @weakify(self);
- [self.locationService requestPermissionsWithCompletion:^(CLAuthorizationStatus completeStatus) {
- @strongify(self);
- [self updateEnrollStatus];
- }];
- completion(YES, nil);
- }
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement