0

每次我们去谷歌地图时都会出现通知。如果我们按取消,然后再次转到谷歌地图,该通知会再次出现。

这是我的代码:

  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
    {
    }

该通知仅显示一次。

4

1 回答 1

0

我的错误是我检查位置是否被授权,如果没有被授权就不要寻找位置。

我应该做的是要求位置开始搜索。这就是警报出现的时候。

[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);
    }];
}
于 2013-04-21T04:44:28.773 回答