views:

261

answers:

2
- (void)applicationWillResignActive:(UIApplication *)application {
    NSLog(@"resigning active status...");
}

i have tried hardware-lock in iphone simulator but this isn't called. I do want to call it in another UIviewcontroller class not in the appdelegate itself.I also added in the viewController's header File.

+1  A: 

I could only get this code to work in the AppDelegate file as well.

You could trying adding your view controller as an observer using the NSNotificationCenter,

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(foo) name:@"AppResigned" object:nil];

Then in the applicationWillResign post the notification,

[[NSNotificationCenter defaultCenter] postNotificationName:@"AppResigned" object:nil];

Hope that helps!

Tom Irving
+1  A: 

According to the documentation, the "applicationWillResignActive" method will get called if the device is locked.

As such pressing Command-L (or "Hardware" >> "Lock"" in the menu) will cause the iPhone simulator to lock and hopefully trigger this method.

Jack