iPhone: View/Close button click action on push notification message dialog - iphone

Could anyone please tell me how to handle push notification dialog's view and close button click from my application? I have gone through this thread which says to handle it in ViewDidLoad but when I click View button, this method doesn't get invoked. I want to do take user to some particular view on View button click and record the Close button click on my Server. So basically I want to know what happens when this button(s) clicked? I have gone through Apple docs but it nothing say about these actions. Any documentation and/or code sample would be really greatful.
Thanks.

If user clicks view then you can catch that action in didFinishLaunchWithOptions method of AppDelegate class. If user clicks close then, there is no way for application to catch that. If your application didn't get the notification in AppDelegate class, then either you forgot to register your app for push notification or you didn't send push notification properly to APNS.

Related

When notification fires, "slide to view" shows a specific controller. Is this possible?

I have an app in which I'm using push notifications. What I really want to do is when a user slides to view from the lock screen he should be able to go to a specific view controller, and not just simply open the app.
Is this possible? Can anyone direct me towards right direction?
Thanks a lot!
In your application:didFinishLaunchingWithOptions: method you can check whether your app was started due to a remote notification by looking into the launchOptions dictionary. The key UIApplicationLaunchOptionsRemoteNotificationKey will give you the remote notification, if any, and you would then need to present your view controller.
If your app is still running while the remote notification arrives your app delegate's application:didReceiveRemoteNotification: method is called.
See the UIApplicationDelegate documentation.
The app needs to figure out and show the right view controller when it is opened after a push notification.

Dismissing a UIAlertView

I put an in app purchase into my app, and when the user taps a button, the purchase is started. So basically, they tap the button, and then depending on the speed on their Internet connection, they could be waiting for up to ten seconds until a new alert view comes up asking if they would like to buy the product. The user will probably tap the button multiple times since nothing came up, and then multiple purchase alert views will come up. Additionally, this could maybe be seen by the user as an app bug. In the end, this is a problem.
I want an alert view to come up with a spinning wheel that says "Loading..." when the users taps the buy button. Now my problem is, how do I get that to dismiss when the new alert view comes up asking the user if they want to buy the product?
if ([UIAlertView alloc] that says: #"whatever Apple's alert view says")
{
//dismiss the "Loading..." alert view here
}
I doubt that would work, so any input is appreciated. Thanks!
You need to have access to that alertview. You can do this. Create a alertview instance var in app delegate and when you want to show loading initialize that instance var assign to your property and when you want to dismiss just call
[alertViewinstance dismissWithClickedButtonAtIndex:0];
Write this piece of code in a method in appDelegate. Hope you get the idea. If not let me know I'll post the sample code here.

iphone: what event will be fired if we close a notofiaction without viewing it

I have a situation say I have to print Notification viewed when local notification is viewed and Notification closed when close button of notification is clicked basically I want to know if we have an event/method which is fired once the notification's cancel button is pressed.
If this is not possible then do we have a method which got fired when the notification is displayed or pushed?
Please shed some light on this.
Your app isn't running, so there is no way to interact with the OS.
The OS will display the localnotification, thus there is no way to either check if the notification is displayed or the cancel button is pressed.

Can i get the push notification's custom properties when the app is closed or background running?

in iphone,can I get the push notification's custom properties when the app is closed or background running?
When an app(not running) received a push, system generate an alert with two buttons: "Close" and "View". If the user taps View, the application is launched. my question is can i change the action of the "View" button, such as open a web link?
I'm not sure that understood what you need...
Think isn't possible... Only things you can change is button (and body) text. More info you can find in Table 3.2. One of the solution could be, to automatically open a web link, when application is launched from push notification.
If the action button is tapped, the system launches the application and the application calls its delegate’s application:didFinishLaunchingWithOptions: method (if implemented); it passes in the notification payload (for remote notifications) or the local-notification object (for local notifications). If the application icon is tapped, the application calls the same method, but furnishes no information about the notification.

Deferentiating the push notification handler when application is foreground and background

It is said that (correct me if I'm wrong) if the application is in the foreground we have to handle push notifications in the "didReceiveRemoteNotification" and if the application is in the background using "didFinishLaunchingWithOptions" when user taps the "view" button of the app. As I dont have a phone to test I want to know whether I am handling this properly.
1) What will be invoked when I taps on the "View" button in the push notification?
2) Let say I am running the application in the foreground and push notification receives at the same time. Will I be given the push notification alert? If so what will happen if the user click on the View button?
3) In this thread How to handle push notifications if the application is already running? it says:
"alert" key will not be there directly under the userInfo dictionary, you need to get another dictionary with name "aps" and then get the "alert" or "body" from "aps" dictionary"
Is this true?
4) I need to push to a certain view when the user clicks on the View button. Hence do I need to handle that code in both methods?
Thank you
There's a nice rundown of the methods invoked by a push notification in this Apple vid: http://developer.apple.com/videos/iphone/#video-advanced-pushnotification - make sure you visit download the full version in iTunes.
This direct link might work: http://developer.apple.com/itunes/?destination=adc.apple.com.3391495696.03391495702.3416205190?i=1378617410
Either way, the general idea is that if your app isn't in the foreground, tapping your view button will trigger didFinishLaunchingWithOptions, and if it is the foreground app, you'll get the didReceiveRemoteNotification.
I don't think you'll get the alert. The method didReceiveRemoteNotification will be called, and it'll be up to you to show a UIAlert if you want.
Yes - that's true.
Yes, but I think you can simplify this by creating a third method specifically designed to handle your view. You can call this from both didFinishLaunching (only if it launched via a notification), and didReceiveRemoteNotification. This way, if your app needs to be launched, you can have time to do any other setup you might need to do for the app to work right out of the get-go (load saved data, init tabbar controllers or anything else like that).
Best of luck