Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios didUpdateUserLocation未使用背景更新触发内部视图_Ios_Objective C_Mkmapview_Mapkit - Fatal编程技术网

Ios didUpdateUserLocation未使用背景更新触发内部视图

Ios didUpdateUserLocation未使用背景更新触发内部视图,ios,objective-c,mkmapview,mapkit,Ios,Objective C,Mkmapview,Mapkit,我有一个应用程序使用后台位置更新,它需要不断跟踪设备的位置,无论应用程序是在前台还是后台。我在应用程序代理中设置了背景跟踪 在前端,我有一个UIViewController和一个工作的mapkit视图,所有CCLocationManager代码触发都没有错误,但在自定义UIViewController类中从未触发didUpdateUserLocation 背景位置跟踪绝对没有问题 下面是我在viewDidLoad中使用的代码 [self.mapView setShowsUserLocation:

我有一个应用程序使用后台位置更新,它需要不断跟踪设备的位置,无论应用程序是在前台还是后台。我在应用程序代理中设置了背景跟踪

在前端,我有一个UIViewController和一个工作的mapkit视图,所有CCLocationManager代码触发都没有错误,但在自定义UIViewController类中从未触发didUpdateUserLocation

背景位置跟踪绝对没有问题

下面是我在viewDidLoad中使用的代码

[self.mapView setShowsUserLocation:YES];
[self.mapView setShowsPointsOfInterest:YES];

self.locationManager = [[CLLocationManager alloc] init];
[self.locationManager requestWhenInUseAuthorization];

self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;

self.locationManager.distanceFilter = kCLDistanceFilterNone;
[self.locationManager setDelegate:self];

if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
    [self.locationManager requestWhenInUseAuthorization];
}

NSString *error;
if (![CLLocationManager locationServicesEnabled]) {error = @"Error message";}

CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
if (status == kCLAuthorizationStatusRestricted || status == kCLAuthorizationStatusDenied) {error = @"Error message";}

if (error) {NSLog(error);}
else
{
    status = [CLLocationManager authorizationStatus];

    self.locationManager.pausesLocationUpdatesAutomatically = NO;
    self.locationManager.activityType = CLActivityTypeAutomotiveNavigation;

    [self.locationManager stopMonitoringSignificantLocationChanges];
    [self.locationManager startUpdatingLocation];
}
任何帮助都将不胜感激
谢谢

您需要查看以下详细信息:

  • 在模拟器上测试这个??didUpdateLocations必须在实际设备上进行测试

  • 请确保您指定了NSLocationAlwaysSusageDescription字符串,否则应用程序将不会显示授权消息,您也不会被授权

  • 您是否已实施locationManager:didFailWithError:?你有什么错误吗

  • 您是否已实现locationManager:didChangeAuthorizationStatus:?您是否以成功授权状态接到此呼叫


  • 我终于解决了这个问题

    事实证明,即使您在Schema和Xcode中使用位置信息,您仍然需要通过Debug>location在模拟器中进行设置


    希望这对其他人有所帮助。

    现在,对于iOS 9,任何更新都需要包括以下内容:

    if ([ locationManager respondsToSelector:@selector(requestWhenInUseAuthorization  )])
        {
         locationManager.allowsBackgroundLocationUpdates = YES;
    
        }
    

    否则,后台更新将受到影响。

    1。模拟器上的测试工作正常,背景位置的变化从模拟器工作没有问题。2.是的,否则背景更新位置也无法工作。3.没有错误4。授权成功进行,没有任何错误。这可能非常愚蠢,但您是否忘记定义要使用的ViewController@界面ViewController:UIViewController订单是否重要?UIViewController我刚才也检查过,得到的kCLErrorDomain代码为0。我在模式中设置了一个默认位置,但顺序不重要。但根据您提到的错误,网络似乎不可用。或者,您需要重置网络设置和位置设置。如果选中了“方案/编辑方案/选项/允许位置模拟”,但未在模拟器上设置默认位置,则会显示所述错误。