每次我们去谷歌地图那个通知出现了。如果我们按取消,再次转到谷歌地图,通知会再次出现。
这是我的代码:
while (false);
static NSDate * lastSearched = nil;
NSDate * dNow=[NSDate date];
NSTimeInterval ti = [dNow timeIntervalSinceDate:lastSearched];
if (ti<60) {
return;
}
lastSearched =dNow;
CLAuthorizationStatus clAuth= [CLLocationManager authorizationStatus];
if (clAuth ==kCLAuthorizationStatusAuthorized)
{
}
else
{
}
该通知只出现一次。
答案 0 :(得分:1)
我的错误是我检查位置是否已获得授权,如果未经授权,请不要寻找位置。
我应该做的是要求位置开始搜索。警报出现的时候。
[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;
}
应该是什么: 直接在这里与授权状态无关。使用授权状态来决定是否应该等待updatelocation
[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);
}];
}