ios - Suspend a certain method until CllocationManager finish -
i have method (methoda) executed when application enters foreground using uiapplicationwillenterforegroundnotification
before calling these method phone call cllocationmanager
's startupdatinglocation
method, want methoda executed when startupdatinglocation
finish, tried that:
- (void)applicationenteredforeground:(nsnotification *)notification { dispatch_queue_t queue = dispatch_get_global_queue(dispatch_queue_priority_default, 0); dispatch_group_t grouping = dispatch_group_create(); dispatch_group_async(group, queue, ^{ [self.manager startupdatinglocation]; }); dispatch_group_notify(group, queue, ^{ [self methoda]; }); }
the problem methoda
still called before startupdatinglocation
finish, thought how that?
the short reply is: don't. that's not how location manager , other async ios frameworks designed.
as onik says, should set object (usually view controller) location manager's delegate.
search in xcode help cllocationmanagerdelegate
. you'll want locationmanager:didupdatelocations:
method.
when locationmanager:didupdatelocations:
method called when location update available. you'll want check location update create sure isn't old, , create sure accuracy value acceptable. (the first reading location manager can old cached location reading lastly time gps active. after that, first few updates can have bad accuracy values. can take 10 seconds or more gps settle downwards , start giving reasonable readings, , never (especially indoors.)
ios objective-c cocoa-touch
No comments:
Post a Comment