Advertisement
Guest User

Setup Action Location

a guest
Jul 12th, 2019
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ////////////////////////////////////////////////////////////////////////////////
  2. // by Roman Shelep
  3. ////////////////////////////////////////////////////////////////////////////////
  4.  
  5. #import "YMSetupActionLocation.h"
  6. #import "CCLocationService.h"
  7. #import "NSObject+FactoryHooks.h"
  8. #import "NSError+CCTableFormManager.h"
  9.  
  10. NSInteger YMLocationServicesDisabledInSettingsErrorCode = 1234;
  11.  
  12. @implementation YMSetupActionLocation
  13. {
  14.  
  15. }
  16.  
  17. - (void)typhoonDidInject
  18. {
  19.     [self setText:@"Allow" forState:YMSetupActionStateToDo];
  20.     [self setText:@"Location Services" forState:YMSetupActionStateBlocked];
  21.     [self setText:@"Location Services" forState:YMSetupActionStateComplete];
  22.    
  23.     @weakify(self);
  24.     self.locationService.didChangeAuthStatusBlock = ^(CLAuthorizationStatus status) {
  25.         @strongify(self);
  26.         [self updateEnrollStatus];
  27.     };
  28.    
  29.     [self updateEnrollStatus];
  30. }
  31.  
  32. - (void)updateEnrollStatus
  33. {
  34.     self.state = [self.locationService isLocationServiceEnabled] ? YMSetupActionStateComplete : YMSetupActionStateToDo;
  35. }
  36.  
  37. - (void)enrollWithView:(id<CCGeneralViewInput>)view completion:(YMSetupCompletion)completion
  38. {
  39.     CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
  40.     if (![CLLocationManager locationServicesEnabled] || status == kCLAuthorizationStatusDenied) {
  41.         NSError *error = [NSError errorWithCode:YMLocationServicesDisabledInSettingsErrorCode name:nil localizedDescription:nil];
  42.         completion(NO, error);
  43.     } else {
  44.         @weakify(self);
  45.         [self.locationService requestPermissionsWithCompletion:^(CLAuthorizationStatus completeStatus) {
  46.             @strongify(self);
  47.             [self updateEnrollStatus];
  48.         }];
  49.         completion(YES, nil);
  50.     }
  51. }
  52.  
  53.  
  54. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement