iPhone如何在iPhone屏幕休眠时告知应用程序

iPhone如何在iPhone屏幕休眠时告知应用程序,iphone,screen,sleep,userlocation,Iphone,Screen,Sleep,Userlocation,我正在制作一个使用用户位置的iPhone应用程序,但是我注意到当iPhone屏幕休眠/关闭时,手机仍然使用用户位置。有没有一个函数可以告诉我屏幕何时休眠,这样我就可以停止更新位置了 @interface RideauAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> { UIWindow *window; UITabBarController *tabBarControl

我正在制作一个使用用户位置的iPhone应用程序,但是我注意到当iPhone屏幕休眠/关闭时,手机仍然使用用户位置。有没有一个函数可以告诉我屏幕何时休眠,这样我就可以停止更新位置了

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

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

@end
@接口RideauAppDelegate:NSObject{
UIWindow*窗口;
UITabBarController*tabBarController;
}
@属性(非原子,保留)IBUIWindow*window;
@属性(非原子,保留)IBUITABBARCONTROLLER*tabBarController;
@结束
您可以使用:

- (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

}

这里的堆栈溢出主题中已经包含了很多有用的信息:这只是AppDelegate中的一个函数。如果使用此选项,我将如何在其他控制器中访问CLLocationManager变量,以便调用[locationManager StopUpdateingLocation]?您的控制器是您的委托的属性吗?它是my tabBarController的一部分,my Delegates的属性您的tabBarController是在您的委托中声明的吗?所以你的控制器也应该在那里实例化?保留代码,因为它似乎是其中一个答案要求的。@Abizern谢谢,我自己还没有足够的特权来做这件事。。。