0

I'm using location services in my app. When the user tapped the startbutton it has to run also in the background. When the user dismisses the app without tapping the startbutton location services has to be stopped. I have to start in when loading the app thus initialzing locationservives when tapping the startbutton is not an option.

I'm tryiing this in my appDelegate.m:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
if([[NSUserDefaults standardUserDefaults] objectForKey:@"appRunning"] == nil) {
    [location stopUpdatingLocation];
    [[NSUserDefaults standardUserDefaults] synchronize];
    NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
}
}

in both applicationWillResignActive and applicationDidEnterBackground.

in the appDelegate.h is this:

#import <UIKit/UIKit.h>
#import "MapKit/Mapkit.h"

@class MainViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate, MKMapViewDelegate, CLLocationManagerDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) MainViewController *mainViewController;
@property (strong, nonatomic) CLLocationManager *location;
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@property (nonatomic) BOOL disclaimerAccepted;

@end

I want to achieve that locationservices is stopped (and the arrow disappear) when the user dismisses the app without having tapped the start button. How can this be done?

BTW I can NSlog the flag in both methods when the NSLog statement is outside teh if statemen so the metods are "seen" just dif statement is not working (so it seems)

4

1 回答 1

0
- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [location stopUpdatingLocation];
}
于 2013-05-09T11:01:54.500 回答