iPhone 6 and 6 Plus comes with a Reachability feature to pull down the screen. Is there an API to notify an app when the user double-taps the home button?
when user double tap home button only below method will be called from AppDelegate.
1) Double tap home
-(void)applicationWillResignActive:(UIApplication *)application
when tap on app below method will be called
- (void)applicationDidBecomeActive:(UIApplication *)application
2) single tap below method will be called
1)- (void)applicationWillResignActive:(UIApplication *)application
2)- (void)applicationDidEnterBackground:(UIApplication *)application
Maybe this will help you.
Related
I'm testing this on iOS 8.4 on Xcode simulator and on an iPhone 6. My notifications work fine and fire perfectly. But I can't figure out how to cancel the notifications when the user quits/closes the app. Pressing home button should NOT cancel the notifications and should still fire the notification.
This is what I have tried.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
return YES;
}
[[UIApplication sharedApplication] cancelAllLocalNotifications];
For the below method - it cancels the notifications when user presses Home button but or closes the app which is not what I want.
- (void)applicationDidEnterBackground:(UIApplication *)application
For below method - notifications will not cancel for home button or closing the app.
- (void)applicationWillEnterForeground:(UIApplication *)application
For below method - it does not execute the method at all for home button or closing the app.
- (void)applicationWillTerminate:(UIApplication *)application
I have looked into other similar questions posted on stack overflow but can't seem to get any of those suggestions to work. Please advise.
Once you fire the Notification it will be registered in the OS. OS presents the notification in time. You cant delete the notification after the application is terminated. No method will be called at the time of Termination.
When a notification arrives if your app is in foregroung didReceiveLocalNotification method will be called.
If you are in background DidLaunchwithOption method is called.
If the app is terminated no method is called.
You fire silent notification and present the actual notifications when you receive silent notifications in these methods. You can use userinfo to identify your notifications.
(void)applicationDidEnterBackground:(UIApplication *)application
Transitioning to the background, i.e when Home Button is pressed.
(void)applicationWillEnterForeground:(UIApplication *)application
Called when transitioning out of the background state
(void)applicationWillTerminate:(UIApplication *)application
Called only when the app is running. This method is not called if the app is suspended.
So, you won't be able to cancel notification, when app is about to be terminated. Therefore, you should choose some other mechanism to delete the Local Notifications. Like create a button to cancel all notifications or something like that.
I want to check every time the app launches whether or not there's a URL in the clipboard, and if so, do something with it. Which method fires that I can override whenever the app launches, whether from a cold launch (it was killed in the background for instance) or if I just press the home button, copy a URL and jump back in.
Is it one of these?
- (void)applicationDidBecomeActive:(UIApplication *)application
- (void)applicationWillEnterForeground:(UIApplication *)application
- (void)applicationDidBecomeActive
- (void)applicationDidFinishLaunching:(UIApplication *)application
Confused.
As #rmaddy says, the correct method to use once the app launched is applicationWillEnterForeground: from your app delegate.
This method will be called when the user jump backs in, but NOT in other circumstances you don't need to respond to (such as the user receiving a text message and dismissing it).
However, from my testing, applicationWillEnterForeground: is not called when an app is launched from cold; you should catch that in applicationDidFinishLaunchingWithOptions:.
So, basically, your app delegate should include code like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self checkForURL];
...
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
[self checkForURL];
...
}
- (void)checkForURL{
//code for checking for URL goes here
}
Hope that helps.
- (void)applicationDidBecomeActive is called when the app is launched or becomes active from the background.
This doc explains everything pretty well: http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html
With reference to the UIApplicationDelegate Protocol, the handling of app launches can be handled in 2 methods:
application:willFinishLaunchingWithOptions:
application:didFinishLaunchingWithOptions:
And the handling of app launches from background can be handled with the help of method:
applicationDidBecomeActive:
Based on the above call, you can handle your application.
In your app delegate add it to the methods that the other answers have suggested (applicationDidFinishLaunchingWithOptions:). In your root view controller register for the following notification. This will always be called when your application launches once it has already started running.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(bringingItBack) name:UIApplicationWillEnterForegroundNotification object:nil];
This will cover both the instances when the app launches and when you are just bringing it back from the background.
I am making an iPhone application that is fairly simple. All I need to do is set the bool "paused" to true to pause the game. How can I make my application do that when the home button is hit?
Thanks guys, that was exactly what I wanted. Since it is in the appDelegate, though, I can't access the boolean "paused" to change it. How can I make it global so that I can access it from the appDelegate?
The Appdelegate.m of your app provides functions you can use to track if the Application will be entering the background;
User pressed the button;
- (void)applicationWillResignActive:(UIApplication *)application
Application is in the background;
- (void)applicationDidEnterBackground:(UIApplication *)application
Within any of these functions you could set the BOOL to True/YES. -> See the comments provided by Apple within the functions for their exact usage.
When the application becomes active again, the appdelegate will (again) fire a function;
- (void)applicationDidBecomeActive:(UIApplication *)application
In your AppDelegate there are two method which is called when the button is called
You can pause the game here:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
//Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
}
or here:
- (void)applicationWillResignActive:(UIApplication *)application{
//Sent when the application is about to move from active to inactive state.
}
In your app delegate, implement applicationWillResignActive:. Set paused = YES; there.
Reset it in applicationDidBecomeActive:.
- (void)applicationWillResignActive:(UIApplication *)application
implement your pause method and it will be called when your app is going to become inactive.
I'm trying to perform some task when a user gets a push notification and presses VIEW. I don't want the app to just launch like it normally does, I want to perform some other task.
What method gets called when the user gets a push and presses VIEW?? didFinishLaunchingWithOptions doesn't seem to get called (not on iPhone 4 anyways).
I basically want something to happen when a user presses VIEW, and only when they press VIEW.
Thanks.
Are you sure application:didFinishLaunchingWithOptions: is not being called? Normally you can tell that your app was launched from the user clicking on the view button of a remote push notification by inspecting the launchOptions parameter.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary *pushInfo = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (pushInfo)
{
// app was launched from a remote push notification
}
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
How can I detect when a user exits the application? (hitting the home button)
And how can I detect when the relaunch it? (clicking the icon)
*I'm not talking about users manually quitting the app by holding the home button and then making the icons wiggle and deleting the app instance from the sub-dock. i'm talking about just temporarily exiting the app buy clicking the home button.. maybe sending a text or whatnot then coming back to the app.
Thanks!
- (void)applicationDidEnterBackground:(UIApplication *)application
and
- (void)applicationDidBecomeActive:(UIApplication *)application
In your AppDelegate.m
- (void)applicationWillTerminate:(UIApplication *)application
There's a notification UIApplicationDidGoToBackground that fires when the home button is pressed. A similar notification tells you about going back to foreground.