is there a notification when "slide to unlock" has occurred - iphone

I have an iphone game that plays background music using AVSoundPlayer - when someone locks the iphone the music stops which is fine. But when someone unlocks it, I don't want my music to start playing again while you're staring at the "slide to unlock" screen - I want it to start playing once you've actually slid the button and the app is visible again - is there some way to detect this? (I've tried applicationDidBecomeActive but that fires when the phone is unlocked but not when your app is visible yet...)

You could try viewWillAppear.

- (void)applicationDidBecomeActive:(UIApplication *)application;
This sent when your app becomes active
Another answer on SO applicable to your question:
applicationWillTerminate works as long as I don't switch off the iPhone

Related

iphone home button event

I am developing a iPhone application and would need to track the home button pressed event by user while the app is in background mode.I have go through the apple documentation/apis but could not find out any to track.
It would be great if anyone can help me on this to track the iPhone home button pressed event.
Your application can't catch any events while in the background. There are some special cases which allows your app to do some tasks in the background, but even them wouldn't allow you to listen to Home button interaction.
You cann't track the home button pressed or not but as your situation is to see if application went in background or not. for this there is a method applicationDidEnterBackground:(UIApplication *)application. This method is called as the application enters into background.
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSLog(#"Application Entered Into Background.");
}

How to handle home button - iPhone/iPod

I am developing a game for the iPhone. I do not actually have an iPhone, so I am testing my game on an iPod device (version 4.2.1). When I press the home button the game starts from level one. I find this odd, since in the simulator, after pressing the home button, the game starts from the same state where I stopped. I am unsure as to why the behavior is different on the iPod, maybe I need to handle the AppDelegate method differently (is it not handled automatically depending upon the device?)
How can I handle this issue?
It appears that the device you are testing your app on does not support multi tasking.
The older iPod touches and iPhones do not support multi tasking an close the app rather than suspending them.
All device that can run iOS 4.3 or higher will support backgrounding. Devices that can't update above 4.2.1 will not support backgrounding and app will be closed if you press the home button.
You will need to save the game state in the apps delegate applicationWillTerminate:
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
Save the current game state here and read them in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

iOS view offset after youTube video execution

I am calling a youtube channel on a UIWebView. When user selects a video, device launches its video player as normal. However, when video ends or user finishes it returning to view, an offset is applied to whole app!! All views have an offset on top but this only happens on iPad and iPad simulator with compatibility mode, on iPhone and iPhone simulator not! How to solve it? Thank you.
Problem is that status bar dissapears after video execution.
[[UIApplication sharedApplication] setStatusBarHidden:NO]; problem is beeing solved when an event is fired using NSNotificationCenter

iPhone - Need to replay background sound when it comes to foreground from background

My application plays a background music when it launches. It stops when I quit the application. But not playing the music again when I open my application. The application has 2 views and I want to play background sound on only main view. So when the app launches it should play the sound until user quit the app or when the user goes to the second view in the app. The sound should be played again only when the user returns to the main view. Currently, I am calling the sub function which plays the sound in 'viewDidLoad' function. please help.
Thanks
Try using this method in your AppDelegate:
- (void)applicationDidBecomeActive:(UIApplication *)application
DidBecomeActive Apple Documentation

Is there a way in iOS to observe the home button being pushed?

I am basically trying to make the device play a sound whenever the app exits (even if the phone is being turned off, the sound would play while the button is being held down). Is this possible?
You could try the - (void)applicationWillResignActive:(UIApplication *)application UIApplicationDelegate method.
Alternately, you could listen for the UIApplicationWillResignActiveNotification notification.