How to set action for UILocalNotification "CLOSE" button? - iphone

How to set action for UILocalNotification "CLOSE" action? If the user click the "CLOSE" button, at the time I will stop the audio player. Is it possible to do this?
I need some suggestions about this feature.
Please help me. Thanks in advance.

You can't detect the close or view button on an UILocalNotification because the notification is handled by iOS and not your app.
If the user decides to view the notification, your app will be started or brought to the foreground and then your app will receive the notification that the user used to open the app.

No, it is not possible to do this. We don't get any event for this.

Yes it is possible you need to create on delegate method and in that method you need to stop your audio player or else when you are calling close button action at that time you need to stop your audio player.

Related

I want eject any user action until a function is done, iphone app!

i'm writing an iphone app integrate with webservice.When user wait to login on web,I want eject any user action until login is done. Please help me! thanks!
One way would be to pop up a modal view controller using presentModalViewController. Another way would be to use [[UIApplication sharedApplication] beginIgnoringInteractionEvents]
If you don't multithread your code the user shouldn't be able to interact with your UI while you're getting and sending data.
Alternatively you could present a semitransparent loading screen over the whole UI -while loading- that intercepts every touch event.

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.

Is there a way to make my background iPhone app to go foreground?

Is there a way to make my background iPhone app to go foreground?
Tnx.
A UILocalNotification will bring the app to the foreground if the device is locked, a notification appears, and the user unlocks the device.
A UILocalNotification with an alertAction will display the alert while the device is unlocked, and if the user taps the View button (or whatever you set it to), your app will be brought to the front.
Not for your app, but the user could do it.
You could schedule a UILocalNotification to inform the user that you are done with your task or whatever.
Nope. But you can do something when you feel must do. For example, use remote Apple Push Notification Service (APNS) to notify your user that you want her to bring your app back to the foreground.
Or, as JustSid put it, use local notification to notify your user that you want her attention.

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

How to close an application programmatically when the user taps on a button

I need to close the application whenever user taps on the button(i need to keep IBAction for closing the app).Like in games menu we have exit button when we tap on it we come out from the game.Same thing i need.How can i do this .Thanks in advance
Please see:
How do I programmatically quit my iPhone application?
WARNING: It is possible to quit the
application by calling exit.
Applications calling exit will appear
to the user to have crashed, rather
than performing a graceful termination
and animating back to the Home screen.
Such usage provides a negative
experience and is strongly
discouraged.
Instead of it, If you want your app to terminate when the user presses the home button, set the value of UIApplicationExitsOnSuspend to YES in your app's Info.plist file. If you do this, when the user taps the home button the applicationWillTerminate: method of your app delegate will be called and then your application will terminate.
exit(0); will terminate your application, but as i know we can not call exit(0); or terminate in an iPhone application. Instead we can put an alerview without button, "saying please quit the application".
This is the best way to do this
UIApplication *myapp = [UIApplication sharedApplication];
[myapp performSelector:#selector(suspend)];
Include this code where ever you need thats it. But still not recommended by apple
Developer apple link
There is no API provided for gracefully terminating an iPhone application. Under the iPhone OS, the user presses the Home button to close applications. see link text
There's one non-recommended way that crashes the app:
[[UIApplication sharedApplication] sendAction:SIGKILL to:[UIApplication sharedApplication] from:self forEvent:nil];
The app will not close the proper way or save. It's more recommended to use a UIAlertView with no buttons to force the user to close the app.
exit(0) is not apple standard way to exit the app and apple highly discourages it.Though, sometimes it approves some application.Give proper UI to show if any functioning is not working or give suggestions regarding it to user.killing app programmatically is not right way.Let user Handle the exit on their own.