objective c - iOS 8 Error when requesting Authorization -
objective c - iOS 8 Error when requesting Authorization -
i having much problem trying requesting location services authorization. know there other posts on forum, did not solve problem solution.
this error popping in xcode:
trying start mapkit location updates without prompting location authorization. must phone call -[cllocationmanager requestwheninuseauthorization] or -[cllocationmanager requestalwaysauthorization] first.
i have added both required keys plist.
another of import point when start in simulator, can go setting manually , enable location services , app work. however, when restart app not work , same message above.
i want prompt user alternative enable location services. unfortunately, code not prompt authorization location services.
please help have been pulling hair out hours. 1
- (void)viewdidload { [super viewdidload]; self.locationmanager = [[cllocationmanager alloc]init]; self.locationmanager.delegate = self; if ([self.locationmanager respondstoselector:@selector(requestalwaysauthorization)]) { [self.locationmanager requestalwaysauthorization]; } [self.locationmanager startupdatinglocation]; //initialize map , specifiy bounds self.mymapview =[[mkmapview alloc]initwithframe:self.view.bounds]; //specifcy resizing self.mymapview.autoresizingmask = uiviewautoresizingflexiblewidth | uiviewautoresizingflexibleheight; //show user's location , set tracking mode self.mymapview.showsuserlocation = yes; self.mymapview.usertrackingmode = mkusertrackingmodefollow; //add view!! [self.view addsubview:self.mymapview]; }
and here function want call
- (void)requestalwaysauthorization { clauthorizationstatus status = [cllocationmanager authorizationstatus]; // if status denied or granted when in use, display alert if (status == kclauthorizationstatusauthorizedwheninuse || status == kclauthorizationstatusdenied) { nsstring *title; title = (status == kclauthorizationstatusdenied) ? @"location services off" : @"background location not enabled"; nsstring *message = @"to utilize background location must turn on 'always' in location services settings"; uialertview *alertview = [[uialertview alloc] initwithtitle:title message:message delegate:self cancelbuttontitle:@"cancel" otherbuttontitles:@"settings", nil]; [alertview show]; } // user has not enabled location services. request background authorization. else if (status == kclauthorizationstatusnotdetermined) { [self.locationmanager requestalwaysauthorization]; } } - (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex { if (buttonindex == 1) { // send user settings app nsurl *settingsurl = [nsurl urlwithstring:uiapplicationopensettingsurlstring]; [[uiapplication sharedapplication] openurl:settingsurl]; } }
-(void)locationmanager:(cllocationmanager *)manager didchangeauthorizationstatus:(clauthorizationstatus)status
this delegate method location service can authorizationstatus status
.such kclauthorizationstatusdenied
you call
[self.locationmanager requestalwaysauthorization];
in viewdid load,and monitor authorizationstatus
in delegate method above,if user deny location service,show alertview
objective-c iphone ios8 location-services
Comments
Post a Comment