location - iOS xCode/Objective C - Simple - Display user's city as a label? -


alright i'm making ios app.. incredibly new @ programming apps ios... (i have experience programming, new me)

i trying display user's city & state on screen.. don't know i'm doing wrong. have this: (there's warning says unused variables city , state [i don't know how fix this]).. way single view , i'm using storyboard (i wish didn't have to.. work better code)

#import "voiviewcontroller.h" #import <corelocation/corelocation.h> #import <addressbook/addressbook.h>  @interface voiviewcontroller ()  <cllocationmanagerdelegate>  @property (nonatomic, strong) cllocationmanager *locationmanager; @property (weak, nonatomic) iboutlet uilabel *city; @property (weak, nonatomic) iboutlet uilabel *state;  @end  @implementation voiviewcontroller  - (void)viewdidload {     [super viewdidload];     // additional setup after loading view, typically nib.    }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. }  - (void)startsignificantchangeupdates {     if ([cllocationmanager locationservicesenabled])     {         if (!self.locationmanager)             self.locationmanager = [[cllocationmanager alloc] init];      self.locationmanager.delegate = self;     [self.locationmanager startmonitoringsignificantlocationchanges]; } }  - (void)stopsignificantchangesupdates {     [self.locationmanager stopupdatinglocation];     self.locationmanager = nil; }  - (void)locationmanager:(cllocationmanager *)manager didupdatelocations:(nsarray *)locations {     cllocation *location = [locations lastobject];      clgeocoder *geocoder = [[clgeocoder alloc] init];      [geocoder reversegeocodelocation:location completionhandler:^(nsarray *placemarks, nserror *error) {      clplacemark *placemark = placemarks[0];     nsdictionary *addressdictionary = [placemark addressdictionary];     nsstring *city = addressdictionary[(nsstring *)kabpersonaddresscitykey];     nsstring *state = addressdictionary[(nsstring *)kabpersonaddressstatekey];     }];  [self stopsignificantchangesupdates]; }  @end 

updated: (but still nothing on screen... see city , state aren't displaying city , state. here isn't connected.)

#import "voiviewcontroller.h" #import <corelocation/corelocation.h> #import <addressbook/addressbook.h>  @interface voiviewcontroller ()  <cllocationmanagerdelegate>  @property (nonatomic, strong) cllocationmanager *locationmanager; @property (weak, nonatomic) iboutlet uilabel *city; @property (weak, nonatomic) iboutlet uilabel *state;  @end  @implementation voiviewcontroller  - (void)viewdidload {     [super viewdidload];     // additional setup after loading view, typically nib.    }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. }  - (void)startsignificantchangeupdates {     if ([cllocationmanager locationservicesenabled])     {         if (!self.locationmanager)             self.locationmanager = [[cllocationmanager alloc] init];          self.locationmanager.delegate = self;         [self.locationmanager startmonitoringsignificantlocationchanges];     } }  - (void)stopsignificantchangesupdates {     [self.locationmanager stopupdatinglocation];     self.locationmanager = nil; }  - (void)locationmanager:(cllocationmanager *)manager didupdatelocations:(nsarray *)locations {     cllocation *location = [locations lastobject];      clgeocoder *geocoder = [[clgeocoder alloc] init];      [geocoder reversegeocodelocation:location completionhandler:^(nsarray *placemarks, nserror *error) {          clplacemark *placemark = placemarks[0];         nsdictionary *addressdictionary = [placemark addressdictionary];         self.city.text = addressdictionary[(nsstring *)kabpersonaddresscitykey];         self.state.text = addressdictionary[(nsstring *)kabpersonaddressstatekey];      }];      [self stopsignificantchangesupdates]; }  @end 

you storing city & state name in nsstring, not using them shows warning. create label & assign values them label_name.text = city;


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -