Catch remote notification while application is in Background - iphone

Is there a way to catch remote push notification while the application is "running" in Background ?
I have implemented the delegate function didReceiveRemoteNotification, and would like it to catch the remote notification while the application is in Background in the new iPhone OS 4.0
The application is correctly in background, since it keep the old state it was when I press the home button. But the push notification is appearing has a popup just like it should when the application is not running...

Well you just can't... :-( Too bad Apple's hasn't think about this...

Related

can we get iPhone earphone jack plugged in/out event while application is running in background?

I want to perform some event when user plugged in/out earphone in iPhone only application is running in background. Simply explanation, I am running music player in background with earphone plugged in, now after some time I am removing earphone (plugged out), at that time I want to show alert "Earphone Plugged Out".
In foreground, we can get this event, that I researched and got, but if we are running the application in background can we get this plugged in /out event?
You are not able to get event in background while if you app is active, you will get notification. please look on apple docs for more detail.
thanks
Yes you should be able to due that, since you have the AudioSession running for backgeround mode you will recieve the jack unplug notification.
But You can't show a UIAlertView you will have to scheudule a UILocalNotification with the current date as firedate. How ever I as an user will find it very anyoing if an app fires an notification to alert me of an action I performed.

iPhone How to prevent my app from entering background when lock screen?

When press the lock button in app,system will call :
-(void) applicationWillResignActive:(UIApplication *)application and
-(void) applicationDidEnterBackground:(UIApplication *)application
So how can I do to make my app only resignActive but not enter background,and I can run my timer when screen locked(Timer can't execute in background mode).
One method is set the property "Application does not run in background" in .plist to YES,it worked, but my app can never enter background again,however I want it will enter background when press the home button.
Update: I want to play some music in my app at a certain time,just like a music alarm,and I still want it works fine when the screen locked,because keep the screen on may waste a lot of battery,and I don't need to do any thing when user press the home button and exit my app.
Open your Info.plist file and add Application does not run in background. Set value to YES.
Application must have special privileges to do any processing in background such as Audio service/Voip service/Location service.
"I can run my timer when screen locked(Timer can't execute in background mode)"
you cannot run a timer in background which will keep running without using any tentrum and doing so...apple will not accept your application on appstore - that's the worst side if you are targeting appstore...
You can not prevent your app from entering the background. This is decided by the operating system (iOS) and is out of control from applications. However, from reading your updated question, I don't think this is what you need to do.
You can execute background tasks with [UIApplication beginBackgroundTaskWithExpirationHandler;] (see reference). If you want to have something happening after a certain interval, check out [UIApplication scheduleLocalNotification:].
Some services such as VOIP, Audio and CoreLocation are allowed to run in background. Using these for other than their intended purposes (for example, playing silent audio) may risk your app being rejected.
Note that there is nothing you can do to prevent your application from entering the background. It is just that some tasks are allowed to execute in the background. Because of this, you cannot do GUI operations and NSTimers will probably not fire (at least I know some cases where they don't).
It would help knowing what you want to run in the background in order to suggest a solution.
Unless you are playing audio BEFORE the move to background you cannot start audio playback when the app is moved to the background or the screen is locked (which has some weird specifics) suffice to say, its as if you were in the background without actually receiving the applicationDidEnterBackground notification.
The best you can do is schedule a local notification, but in this case your music is limited to 30 seconds and must be part of your application bundle.

iPhone - Differentiate UIApplicationDidBecomeActiveNotification notifications

When registering the UIApplicationDidEnterBackgroundNotification, I notice that this notification is not triggered when the device enters in sleep mode.
But, when waking it up, the UIApplicationDidBecomeActiveNotification notification is triggered. It is also triggered when coming back from background mode.
So how can I know if my application comes back from background mode, or is activated following a wake up of the device ?
Those don't balance each other; they are posted for unrelated events. I believe you want UIApplicationWillEnterForegroundNotification when detecting your app coming back from the background, and UIApplicationWillResignActiveNotification when detecting certain other situations (including sleep.)
Note that UIApplicationWillResignActiveNotification also shows for events such as "incoming phone call was ignored" and "the operating system displayed an alert that is not part of your process" (e.g. a text message.)

Sound in Push Notification iPhone

Is there any way to set (toogle on/off) your push notification alert (after registered to APNS), sound and badge (by Code) inside an application?
I'm sorry the question seems a little ambiguous, actually I want to know
Is it possible to non activate the sound and alert inside the application function (by code) I am working. It is similar as you can disable the sound, alert or badge in iPhone Settings, But I want to do it in code.
It is like Whatsapp app in iPhone, there are some notification setting — we can toggle the alert on or off.
You could make a system where the user can choose a sound. Save that one. And in the method where the push notification comes in. Play that sound. I dont know if this works when the phone is on sleep mode.

Differentiate if the app became inactive because the home button being pressed or an incomming phone call

I know that whenever the app becomes inactive, the UIApplicationWillResignActiveNotification local notification will be posted. In the opposite suituation, the UIApplicationDidBecomeActiveNotification notification will be posted.
A client want the app to act differently according to the interruption, he wants the app to close when the home button but to remain active if the user receives a phone call. It doesn't seem to be possible, I'm correct ?. If It's possible how can I do It ?
Edit: I know how to close my app whenever an interruption is received , my question is if it's possible to differentiate if the cause of the interruption was the home button being pressed or an incomming phone call, so my app responds differently in each case.
Using CTCallCenter notifications allows you to differentiate between incoming call or send-to-background using Home or multitasking tray reasonably reliably.
If you want the app to quit when the home button is pressed, you should set the UIApplicationExitsOnSuspend key to YES in the app's Info.plist file. If you edit the plist in Xcode, this key is displayed as Application does not run in background.
Then you can handle all of your termination in response to the UIApplicationWillTerminateNotification notification (or equivalently, in the appDelegate's applicationWillTerminate: method.
More information here: http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html