If you look at the Execution States for Apps in Apple's App Programming Guide for iOS, it states that:
applicationWillResignActive
:—Lets you know that your app is transitioning away from being the foreground app. Use this method to put your app into a quiescent state.
Compare to
applicationDidEnterBackground
:—Lets you know that your app is now running in the background and may be suspended at any time.
For example, if you press the Home button of your device twice, the applicationWillResignActive
method will be call immediately, your app is in a transitioning
state now. see the image below (Your app leave foreground, but not yet in background):

If you select other app, the applicationDidEnterBackground
of your app will be called, and your app enters background. So it is better to call GCMService.sharedInstance().disconnect()
when your app is actually in a background
state compared to a transitioning
state.
Similarly, applicationWillEnterForeground
vs applicationDidBecomeActive
.
If you are in other app now, and you switch back to your own app, the applicationWillEnterForeground
will be called immediately, but your app is might still in an inactive state(which is currently not receiving events).
It might only last for less than half a second, and applicationDidBecomeActive
will called immediately after. Because applicationWillEnterForeground
is more a transitioning
state. So it is better to call GCMService.sharedInstance().connectWithHandler()
when your app is actually in an active state(app is running in the foreground and is receiving events).
You might think applicationDidBecomeActive
and applicationDidEnterBackground
are asymmetric, but these two methods all have a word Did
. But two other methods have the word Will
, which means a transitioning
state.
You can also see the Life Cycle picture from this StackOverflow answer.
Edit after @user102008's comment:
If you do connect in the applicationWillEnterForeground
method, then connect method wont be called when the app is first launched. Also, the GCM doc says that Call disconnect when the client app is in the background or when it needs to stop exponential background connection retry
, so I think its better to call disconnect when the app is in background, instead of when phone call comes? I think you can use enum with 3 different states connecting
, not connected
and connected
, when the applicationDidBecomeActive
method is called, you can check if its not connected
or connecting
, then you call the connect method again.