IOS9 startMonitoringSignificantLocationChanges does not start the application when it is completed?

I am working on an iPhone application that needs to send the current location to the server so that it knows what push notifications to send. It doesn't have to be very accurate, startMonitoringSignificantLocationChanges is perfect for my needs.

All this works well while the application is running on screen or in the background. However, if I kill / terminate the application, it no longer works. From what I understand, the application should be automatically overwritten with the special launch option UIApplicationLaunchOptionsLocationKey. However, the application does not restart (at least not in the simulator).

I read something too: Behavior for significant location API on completion / pause?

Is an automatic reboot performed only when the application is terminated from a paused state by the system, and not when you manually kill the application? I also tried the special info.plist UIApplicationExitsOnSuspend, which also terminates the application when it goes into the background. It also does not restart.

Is there a way to simulate an application that terminates with a system in a simulator?

What happens after an iOS update when the phone restarts? Is there a way to make sure the application is restarted?

+4
source share
2 answers

SLC , , , , CLLocationManager startMonitoringSignificantLocationChanges. - iOS7.0 (.x) . iOS7.1 +.

.

  • , .
  • NSLocationAlwaysUsageDescription info.plist, , .
  • ,
  • ,
  • .

:

AppDelegate,

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate>

@property (strong, nonatomic) UIWindow *window;
@property CLLocationManager* locationMgr;

@end

AppDelegate.m

#import "AppDelegate.h"

@implementation AppDelegate

@synthesize locationMgr;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    NSLog(@"app launching");

    locationMgr = [[CLLocationManager alloc] init];
    [locationMgr setDelegate:self];
    // Added in iOS8
    if([locationMgr respondsToSelector:@selector(requestAlwaysAuthorization)])
        [locationMgr requestAlwaysAuthorization];
    // Added in iOS9
    if([locationMgr respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)])
        [locationMgr setAllowsBackgroundLocationUpdates:YES];
    [locationMgr startMonitoringSignificantLocationChanges];

    return YES;
}

-(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    NSLog(@"app delegate received significant location change");
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1];
}

@end

"", , . "" , . , , , , . .

iOS SLC.

. CLLocationManager startMonitoringSignificantLocationChanges , stopMonitoringSignificantLocationChanges. , CLLocationManager SLC, , - , .

, .

, , , - SLC.

start, start, stop start, exit - SLC.

+3

Source: https://habr.com/ru/post/1613343/


All Articles