iPhone如何在iPhone屏幕睡眠时告诉应用程序

the*_*ter 3 iphone sleep screen userlocation

我正在制作一个使用用户位置的iPhone应用程序,但是我注意到当iPhone屏幕休眠/关闭时,手机仍在使用用户位置.那么是否有一个功能可以告诉我什么时候屏幕睡觉所以我可以stopUpdatingLocation?

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

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

@end
Run Code Online (Sandbox Code Playgroud)

Nic*_*s S 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

}
Run Code Online (Sandbox Code Playgroud)

  • Stack Overflow主题中已经介绍了很多有用的信息:http://stackoverflow.com/questions/411436/what-happens-to-an-iphone-app-when-iphone-goes-into-stand-by-mode (3认同)