GCM Notifications Not Received When App Is in Background Mode in iOS
Notifications may not be received when the app is in background mode due to the following two reasons:
Solution:
In your PHP file, add the following to the $post array:
<code class="php">'content_available' => true, 'priority' => 'high',</code>
Also, update the $data array to include a body field:
<code class="php">$data = array( 'message' => 'Hello World!', 'body' => 'Hello World!');</code>
In your AppDelegate.m file, ensure that the following code is present in the applicationDidEnterBackground method:
<code class="objective-c">[[GCMService sharedInstance] connectWithHandler:^(NSError *error) { if (error) { NSLog(@"Could not connect to GCM: %@", error.localizedDescription); } else { _connectedToGCM = true; NSLog(@"Connected to GCM"); } }];</code>
By implementing these changes, your app should now receive notifications even when it is in the background.
The above is the detailed content of How to Resolve GCM Notifications Not Received When App Is in Background Mode in iOS?. For more information, please follow other related articles on the PHP Chinese website!