简体   繁体   中英

applicationDidBecomeActive called multiple times in iOS 10

In my app user location allow permission popup flashes many times at the application launch.

My code

AppDelegate.m 

- (void)applicationDidBecomeActive:(UIApplication *)application
{
   [self.shareModel startMonitoringLocation];
}

LocationManager.m

- (void)startMonitoringLocation {
     if (_anotherLocationManager)
        [_anotherLocationManager stopMonitoringSignificantLocationChanges];

    self.anotherLocationManager = [[CLLocationManager alloc]init];
    _anotherLocationManager.delegate = self;
    _anotherLocationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
  _anotherLocationManager.activityType = CLActivityTypeOtherNavigation;
    _anotherLocationManager.allowsBackgroundLocationUpdates=YES;
    if(IS_OS_8_OR_LATER) {
        [_anotherLocationManager requestAlwaysAuthorization];
    }
    [_anotherLocationManager startMonitoringSignificantLocationChanges];
}

In my code applicationDidBecomeActive is called multiple times and therefore locationmanager popups many times at application launch due to which my app was rejected at a recent update

Rejection issue:

From Apple
2. 1 PERFORMANCE: APP COMPLETENESS
Performance - 2.1


We discovered one or more bugs in your app when reviewed on iPad and iPhone running iOS 10.0.2 on Wi-Fi connected to an IPv6 network.

Specifically, your app’s Background Location modal alert continuously appears and prevents access to the app.

Next Steps

Please run your app on a device while connected to an IPv6 network (all apps must support IPv6) to identify the issue(s), then revise and resubmit your app for review.

I have researched for a couple of days but couldnt find the issue in iOS10.

Any ideas/suggestions would be highly helpful & very thankful

Why not add

    [self.shareModel startMonitoringLocation];

in

applicationDidFinishLaunchingWithOptions:

or try :

- (void)startMonitoringLocation {
 if (_anotherLocationManager == nil) {
self.anotherLocationManager = [[CLLocationManager alloc]init];
_anotherLocationManager.delegate = self;
_anotherLocationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
_anotherLocationManager.activityType = CLActivityTypeOtherNavigation;
_anotherLocationManager.allowsBackgroundLocationUpdates=YES;

if(IS_OS_8_OR_LATER) {
    [_anotherLocationManager requestAlwaysAuthorization];
}
[_anotherLocationManager startMonitoringSignificantLocationChanges];
} else {
    [_anotherLocationManager stopMonitoringSignificantLocationChanges];
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM