iphone dev how to check notification's launch button pressed - iphone

I have Implemented Ray wenderlich's these
http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12
http://www.raywenderlich.com/3525/apple-push-notification-services-tutorial-part-2
awesome tutorials on APNS. Every thing is working fine, now what i want is that in case application is not running and notification arrives and displays on device now if user presses the launch button i want to display a particular screen other than home screen (i have tab bar application with splash screen displays first for 5 seconds then home screen displays which is on zero index), means i want to display a screen which is on third index, plz. guide me in this, is there a way to do this? and how thanx and regards... Saad

If you have different flows for when the app is active & for when the app is not active (reg. notifications) you can do it like so -
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if(application.applicationState == UIApplicationStateActive)
{
// app active.
}
else
{
// app not active
self.tabController.selectedIndex = 3;
}
}

Related

Push notification opens app automatically when unlocking an iPad

I have developed the iPad app which uses apple push notification. Push notification delivering works fine in all the scenario except when the iPad device is locked and notification is delivered. In this scenario it behaves weirdly and opens the app when you slide to unlock the device without touching the alert/banner or notification from notification center.
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
[self AgendaView];
}
-(void)AgendaView
{
Agenda_Main *agendaview = [[Agenda_Main alloc]init];
[self.navigationcontroller pushViewController:agendaview animated:YES];
}
This is a feature in iOS.. When u unlock the device, the most recent notification app will be opened..
It works that way when first receiving the alert. If you let the device lock again after receiving it, when you unlock it the next time you will go to Springboard
That is just how iOS works. You'll notice that when the alert comes in, the lock screen will only show information for that alert (it will also be centred on the vertical axis).
If you press the lock button to turn the screen off, then the home button to turn it back on you will see that the notification has now stacked to the top of the window, along with any other notifications. If you unlock the device now it will take you to the springboard, and not the app.

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.");
}

iOS 5 banner push notification disappear, user tap on app icon to start the app

With iOS 5, push notifications can appear as banner and disappear after a few seconds.
I understand that didReceiveRemoteNotification will be called when user taps on the banner.
My question is, if the banner has disappeared and my user sees that there is a badge number on the app, they will tap on the app icon to start the app. Now if the app is running in the background, how do I check that the app is brought to foreground and there has been a notification, and do the necessary?
The purpose of my notification is basically to inform user there has been an update to the app content and encourage them to run the app to get the latest contents. My app only checks for latest contents at launch time and doesn't check for updates periodically.
This question is a bit old, but I'll pop what I've found in here anyway.
There are two methods you need to implement in your app delegate to check if your app was either launched from the remote notification (From when the app is not running on your device), or received the remote notification while running (in the background or foreground).
First is a method that is already in your App Delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
To check if this was launched from a remote notification, have some code similar to this:
// Check to see if launched from notification
if (launchOptions != nil)
{
NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
NSLog(#"Launched from push notification: %#", dictionary);
// DO SOMETHING HERE
}
}
The other method you will need to implement is specifically for the case that your application for when your application is running:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(#"Received notification: %#", userInfo);
}
How you handle the notification from there is up to you, but that's how your app knows about it!
In this second method, you can check the UIApplicationState of the passed application to find out if you were in the foreground or background.

Determine if an app is running in the foreground when a notification is received on iOS

I would like to find a way to see what app is running in foreground or if the home screen is displayed when a local notification from my app show up. For example i want to have different actions if there is in homescreen or in someone else app.
I tried to use processed and pid but the pid is generated hen the app starts and not the last time the app is used.
Any idea?
thanks
As described in the push notification documentation you can read [[UIApplication sharedApplication] applicationState] when you receive the notification to determine whether your app is in foreground, inactive (it's visible but a dialog like the WiFi chooser is in front) or in background.
Just to have a copy-paste code available for others:
if([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive)
{
//App is in foreground. Act on it.
}
Swift 5 version:
import UIKit
let isForeground = UIApplication.shared.applicationState == .active

Push Notification Problem

I want to get the reminder at each notification comes from the web service in the application for the different tasks. For that what i have used the following methods.
but i am not getting push notific
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
}
Receiving push messages in the app
So what happens when your iPhone receives a push notification? There are three possible situations:
The app is currently running in the foreground. Nothing happens on the screen and no sound is played, but your app delegate gets a notification. It is up to the app to do something in response to the notification.
The app is closed, either the iPhone’s home screen is active or some other app is running. An alert view pops up with the message text and a sound is played. The user can press Close to dismiss the notification or View to open your app. If the user presses Close, then your app will never be told about this notification.
The iPhone is locked. Now also an alert view pops up and a sound is played but the alert does not have Close/View buttons. Instead, unlocking the phone opens the app.
I ran into a lot of problems on Push notification. Please note: if you are not getting the device token back, check to make sure the device is connected to the internet. If not device cannot contact the APN server. It took me days to find this out