Location services don't stop when application is terminated

前端 未结 7 1404
感动是毒
感动是毒 2021-01-04 18:28

I\'m currently developing an iPhone application which needs location services for various use including AR.

I test everything on simulator and on my iPhone 3GS and e

7条回答
  •  自闭症患者
    2021-01-04 18:50

    Sounds like you're app is going into the background and still using CLLocation. You can stop CLLOcationManager when you receive notification that you're app is resigning active, that's the best way. Then resume when it becomes active. The answer in this question show how to do that here

    [EDIT] When your app goes into the background or resigns active for any reason (ie: phone call) you should stop location services at that time. You need to subscribe to the notifications and provide a method to stop and start location services, something like this:

    -(void)appDidBecomeActiveNotif:(NSNotification*)notif
    {
        [locationManager startUpdatingLocation];
    }
    
    -(void)appWillResignActiveNotif:(NSNotification*)notif
    {
        [locationManager stopUpdatingLocation];
    }
    
    -(void)viewDidLoad
    {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidBecomeActiveNotif:) name:UIApplicationDidBecomeActiveNotification object:nil];         
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActiveNotif:) name:UIApplicationWillResignActiveNotification object:nil]; 
    }
    
    -(void)dealloc
    {
        [[NSNotificationCenter defaultCenter] removeObserver:self];
        [super dealloc];
    }
    

提交回复
热议问题