3

我正在制作一个使用用户位置的 iPhone 应用程序,但是我注意到当 iPhone 屏幕休眠/关闭时,手机仍在使用用户位置。那么是否有一个功能可以告诉我屏幕何时休眠,以便我可以停止更新位置?

@interface RideauAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
    UIWindow *window;
    UITabBarController *tabBarController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

@end
4

1 回答 1

5

您可以使用:

- (void)applicationWillResignActive:(UIApplication *)application {
    [[[self.tabBarController.viewControllers objectAtIndex:0] locationManager] stopUpdatingLocation]; 
    //if it is your first VC, if not change objectAtIndex: to the correct one

}
于 2011-06-20T18:50:55.293 回答