Allowing the user to acknowledge a UILocalNotification without launching the app - cocoa-touch

Is there any way, when a UILocalnotification is displayed as an alert, for there to only be one action button displayed, rather than both "Close" and "Launch"?
Assuming there is no way, I can change the second action button to say "Continue". I want to be able to register in my app that they did press "Continue" but I don't want the app to actually launch. Is this possible?

It's not possible within current SDK, unfortunately. The push notification alert can have only two actions – either it's cancelled and your application is not notified, or your application is being brought to foreground to handle the notification.

Related

Push notification while app is not running - launchOptions dictionary is empty

I've read a number of questions here on SO regarding receiving push notifications while the application is not running (more than in the background, meaning it is shut down completely). This question in particular is most helpful in figuring out how to determine if one was receiving using the launchOptions dictionary.
However, I'm very confused, and I fully admit this may be a massive oversight on my part: when my device receives a push notification for this application while the app is shut down, and I later open my application, the launchOptions dictionary is a null pointer. From the description of the accepted answer in the previously mentioned link, and other places too, I gather that I should be able to see a notification payload; however there is nothing. I am developing for iOS 5.1.1.
My only other thought is to check the number of badges on start up (greater than zero, do something...), but this seems very unreliable.
Can anyone tell me what I am missing? Thank you in advance for your help!
application:didFinishLaunchingWithOptions: will only be called with payload information when app is launched due to notification. E.g. this could happen if user taps over notification alert (added in notification center) or notification received with content-avialble = 1 in payload (Newsstand notification) & provided your app is not in foreground as well in background.
If your app receives notification when app is in background. If it is Newsstand notification or if user taps over action button of alert below method is called
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
with [[UIApplication sharedApplication] applicationState] not equal to UIApplicationStateActive.
In above case if user does not tap over action button of notification alert and launch app by tapping over it, neither didFinishLaunchingWithOptions or didReceiveRemoteNotification is called.
If your app receives notification while in foreground didReceiveRemoteNotification is called [[UIApplication sharedApplication] applicationState] will be equal to UIApplicationStateActive.
For badge in notification, if your app is not running no code is executed and the badge is incremented by 1 in app icon. When you launch app (tap on app icon) didFinishLaunchingWithOptions is called with normally. (If app is in background or foreground when notification received, same as above)
So I think this covers every possible case. Also note that the background case is valid for iOS SDK >= 4.0

Custom modal dialog and background operations

I have a Cocoa app with a custom, multi-step account setup that I implemented as a custom modal dialog with a set of views.
The problem is that the background operations (fetching a URL) seem to get stuck. I assume that this is because the application is in a modal mode.
Here the code to start the modal dialog:
[NSApp beginSheet:accountSetupController.window modalForWindow:self.window
modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
[accountSetupController beginAccountSetup]; // this later launches the background operation
[NSApp runModalForWindow:accountSetupController.window];
NSApp endSheet:accountSetupController.window];
First of all, is my assumption correct? Is there a way to have the background operation proceed even if the application is running modal?
The actual background operation is not under my control. It is an external API that takes a completion block.
Take a look at the "discussion" section of your call to [NSApplication beginSheet: modalForWindow: ...]:
Discussion
This method runs the modal event loop for the specified sheet
synchronously. It displays the sheet, makes it key, starts the run
loop, and processes events for it. While the application is in the run
loop, it does not respond to any other events (including mouse,
keyboard, or window-close events) unless they are associated with the
sheet. It also does not perform any tasks (such as firing timers) that
are not associated with the modal run loop. In other words, this
method consumes only enough CPU time to process events and dispatch
them to the action methods associated with the modal window.
To me, this means that background threads and tasks aren't running while this modal session is going. I've run into this problem before with my own modal dialogs trying to access web servers (for registration purposes, if I remember correctly).
The best solution is to not use modal dialogs if you need to talk to a server asynchronously. If you must use modal dialogs, try to do your communication between modal sheets (i.e. when the user hits "submit", end the sheet and do the server chatting, then bring up the next sheet for the next step).

How to differentiate lock screen and home button (background multitasking) on applicationWillResignActive in the app delegate

I am writing an alarm clock app.
Please correct me if I am wrong:
On both events (lock & home button in iOS 4.x) the applicationWillResignActive: method is called. When locked my app can keep on running (forever if DeepSleepPreventer.h is used) to check if the alarm should go off. When home is pressed it has to stop working at some time (apart from some basic background calculations). So in this case I have to set a local UILocalNotification to trigger the alarm.
So my question: How to differentiate between those two events?
Thank you!
Have you tried implementing -applicationDidEnterBackground: in your app delegate?

how to load application on button event of push notification in objective c?

I wanted to know whether it is possible to load the application or some specific page on clicking the "OK" button of the push notification or not in objective c.
As i want to load the application when i press the button of the push notification.Kindly help me out if possible.
Thanking you.
the push notification usually have a "View" button that will automatically launch your application. you don't have to do anything in your app for that to work.
when the user launches the application that way, your app delegate receives a call to
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions,
the launchOptions dictionary containing whatever data was added to the push notification payload by the server.
you can check that and open any relevant page or view, or handle that notification anyway you want.

Application Termination

I am running my app on a device. When I am in second view and terminate the app, the app quits but then when i launch it, it goes straight back to second view and not the first view (login view). I checked to see if the control goes to applicationWillTerminate method, but it does not go into that method. How can i make my program go into it?
This is probably due to iOS 4's multitasking. When you tap the Home button, your application is by default suspended on supported devices (if you double tap Home, you can see all suspended applications). You can set the plist key UIApplicationExitsOnSuspend to force UIKit to quit your application, rather than suspend, when the home button is pressed.
If you want to support the multitasking modes, look at the applicationDidEnterBackground: method of your UIApplicationDelegate implementation.