我的错误是我检查位置是否被授权,如果没有被授权就不要寻找位置。
我应该做的是要求位置开始搜索。这就是警报出现的时候。
[singleton.locationManager startUpdatingLocation];
触发警报
如果位置未被授权,那么我根本不应该等待永远不会被调用的更新。
我之前做的:
CLAuthorizationStatus clAuth= [CLLocationManager authorizationStatus];
if (clAuth ==kCLAuthorizationStatusAuthorized)
{
}
else
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
UIAlertView * aV= [[UIAlertView alloc]initWithTitle:@"Can't Get Location" message:@"Update your settings to allow location update. Isikota cannot work without user location." delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles: nil];
[aV show];
}];
return;
}
应该是什么:与授权状态无关,直接到这里。使用授权状态来决定我们是否应该等待更新位置
[BGLoadingView vPermaToastTillFinish:@"Getting Location" inView:
[BGHelperForAllApplication window] doWhat:^{
[self vStartUpdatingLocation];
CLLocationHandler * clhHandler=[self singleton];//This one is a singleton anyway
//[[NSNotificationCenter defaultCenter]addObserver:clhHandler selector:@selector(vLocationFound) name:NotificationManageToGetCurrentLocation object:nil];
CLAuthorizationStatus clAuth= [CLLocationManager authorizationStatus];
PO(clhHandler.operation);
if (clAuth ==kCLAuthorizationStatusAuthorized)
{
[clhHandler haltThisThreadTillUnsuspended];//if not authorized then it'll never finish so don't bother halting
}
while (false);
}];
vStartUpdatingLocation 的内容
+(void) vStartUpdatingLocation
{
while (false);
AssertNonMainThread
[[NSOperationQueue mainQueue]addOperationWithBlock:^{
CLLocationHandler * singleton = [CLLocationHandler singleton];
[singleton.locationManager startUpdatingLocation]; //This one pulls the alert
PO(singleton.locationManager);
while(false);
}];
}