Troubleshooting Push Notification
Push notifications are crucial for keeping your app users engaged and informed. If you're facing issues with push notifications, follow these steps to troubleshoot and resolve the problem. Do not skip any steps. We have covered all scenarios, common mistakes, and even provided you with scripts to bypass mesibo and send push directly.
Step 1: Verify Firebase and Apple Push Credentials
Ensure that you have correctly configured the push credentials for Android (Firebase) and iOS (Apple Push Notification Service) in the mesibo console as described here. Common mistakes include:
Android Firebase Credentials: Double-check that the project and client ID from the uploaded credentials match the ones used for generating the push token.
Apple P12 Certificate: Verify that the bundle ID matches your app's bundle ID. If they don't match, push notifications will be rejected.
Step 2: Check the Push Token
Confirm that you have obtained and set the push token correctly, as described in the documentation. You can verify this by checking the user details in the mesibo console, which should display the push token and will also allow you to send a test push notification.
Step 3: Use Background Push and not Alert
mesibo sends Background Push
notifications by default, which is the recommended configuration. Your app should utilize Background Push
in conjunction with local notifications to display push notifications instead of using alerts. Avoid using alerts unless you fully understand the implications.
Step 4: Check if you are using Firebase Push Tokens for iOS Applications
For iOS applications, it is generally recommended to use Apple Push Tokens instead of Firebase Push Tokens. However, if you decide to use Firebase API to generate push tokens for your iOS app, it is mandatory to upload FCM (Firebase Cloud Messaging) credentials to mesibo. Uploading APN (Apple Push Notification service) certificates alone will not be sufficient.
Additionally, you should refer to the Firebase documentation to properly configure APN certificates in their settings. Since we do not have access to your Firebase settings, we cannot provide much support if you choose to use the Firebase API for your iOS application. We strongly advise using APN and Apple Push Tokens for iOS.
Step 5: General Troubleshooting
Before we describe more advanced troubleshooting using webhooks and enabling push notification debugging in the next step, read through the General Troubleshooting and iOS specific Troubleshooting steps below:
General Troubleshooting
If your app doesn't get the push, check the following:
- Ensure that you are testing push notifications under normal conditions. Your app will not receive push if you "force stop" the app, clean the app cache, etc.
- Ensure that you have configured push-notification credentials for your app correctly on the mesibo consoleopen_in_new.
- Ensure that your phone is not in Do-Not-Disturb mode.
- Keep your phone on the cellular data and see if you are receiving push notifications.
- See if other apps on your phone receive it.
- mesibo sends push only when your app is suspended and disconnected. It may take a few seconds (or minutes) depending on the operating system and also the device configuration.
- Ensure that you are using Background push and not Alert.
Additional Troubleshooting Steps for iOS
- While PushKit is ideal for calls, the iOS 13 and newer mandatorily require CallKit integration and reporting when using Push Tokens which does not go well with Video Calls. If not, iOS will terminate your app. Refer to Apple documentation and WWDC talk Advances in App Background Executionopen_in_new. Also, according to these threads ( hereopen_in_new, hereopen_in_new, and hereopen_in_new), only a few apps (WhatsApp, FB messenger, Telegram) are given special privileges, so unless your app is also given those privileges, we currently do not recommend using Push Kit.
- Use the Production Certificate, not the development certificate. Mesibo console will give you a warning but will accept the certificate. However, your device is likely not to receive push notifications.
- Ensure that the bundle ID on the certificate matches your app bundle ID. Note, if you are using the mesibo demo app, you need to change the bundle ID to match your certificate.
- Don't mess with the
APS entitlements
setting unless you know what you are doing. By default, it is set todevelopment
for the development and set toProduction
by Xcode when you upload your app to the App Store for release or test flight. This setting impacts the selected APN endpoint for sending push notifications. Hence, if you change this to say 'Production', you may need to send all your sandbox pushes to the production APN server
Step 6: Configure Webhook to receive Push Notification Results
If your app still cannot receive push notifications after the above steps, you can debug the issue using webhooks. Enable the Push Notification Results
checkbox in the Webhook settings in the mesibo console. When a push notification fails, you'll receive a webhook request from mesibo containing information about the push event, including the request and the response from FCM and APN.
To enable this, check Push Notification Results checkbox setting in Webhook, in the consoleopen_in_new. When a push notification fails, you will receive a webhook request from mesibo, and the payload will contain information about the push event. In the webhook payload, you can inspect the request and the response so that you can understand the reason for failure or why the push service(FCM/APN) rejected the push. For example, if you did not configure the right credentials, etc.
Refer mesibo Real-time webhooks to know about setting up a webhook and using the push event type to debug failed push notifications.
In the push event, the response.code field will contain the error code which indicates the reason for failure.
If FCM/APN rejected the push, then refer to the respective documentation of push notification error codes.
- For FCM, refer hereopen_in_new
- For APN, refer hereopen_in_new
If Mesibo rejected the push, then the error code will be a value greater than 900
. Refer to the table below for special error codes and their meaning:
Error Code | Description |
---|---|
901 | Push service for the app is not configured |
901 | Push service for the app is temporarily disabled |
903 | Push certificate expired |
904 | Push certificate error |
905 | Production certificate is required for this push |
911 | Bad push token |
912 | Mismatch in APN certificate and the push token app id |
913 | Bad payload |
914 | Ratelimit reached |
Step 7: Enable Push Debugging
You can also enable Push Notification Debugging
from the App Settings -> Push Notifications
in the mesibo console. This will send additional data over the webhook, even for successful pushes. However, since debugging requires more CPU resources, you can enable push debugging for 3 hours out of every 8 hours.
Troubleshooting using Custom Scripts
Another troubleshooting option is to send a push notification yourself and see if it helps. Use one of the scripts below to send push notifications to your device. Once it is working, you can set up the mesibo webhook, which will be invoked when the destination is offline. You can then send push notifications from the webhook using your custom scripts. You can also use webhooks to inspect the push request sent by mesibo and the response received from FCM/APN. See Debugging Push Notifications using Webhooks.
Use the following PHP script to send push notifications to Android devices.
<?php
function android_push($to) {
$apiKey = 'FCM API KEY'; // for legacy FCM only
$url = 'https://fcm.googleapis.com/fcm/send';
$priority = "high";
$type = "data"; // or 'notification' .
$message = "none"; // your message
$topic = ''; // not using, https://developers.google.com/cloud-messaging/topic-messaging
$collapse_key = 'NEWMESSAGE';
// there are two kinds of messages, data (default priority normal) and notification (default priority high).
$fields = array(
'to' => $to,
'priority' => $priority,
'collapse_key' => $collapse_key,
$type => array( "message" => $message ),
);
$headers = array(
'Authorization: key=' . $apiKey,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the URL, number of POST vars, POST data
curl_setopt( $ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_POST, true);
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields));
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
$r = json_decode($result, 1);
if(isset($r['failure']) && $r['failure'] > 0) {
print_r($r);
return false;
}
return true;
}
Use the following PHP script to send push notifications to iOS devices.
<?php
$token = "Client Token";
// APN certificate
$certificate = 'universal_cert.pem';
$alert_message = '{"aps":{"action":"message","title":"your_title","body":"your_message_body"}}';
$message = '{"aps":{"content-available":"1"}}';
$apn_server = 'https://api.development.push.apple.com'; // or 'api.push.apple.com' if production
// change this to match your certificate and app bundle id
$bundle_id = 'com.mesibo.app';
$status = apn_push(true, "background", $apn_server, $certificate, $bundle_id, $message, $token);
echo $status;
//type can be alert,voip, etc. Refer to APN documentation
function apn_push($production, $type, $apn_server, $certificate, $bundle_id, $message, $token) {
$apn_server = 'https://api.development.push.apple.com';
if($production) {
$apn_server = 'https://api.push.apple.com';
}
$url = "{$apn_server}/3/device/{$token}";
$cert = realpath($certificate);
// headers
$headers = array(
"apns-topic: {$bundle_id}",
"User-Agent: mesibo",
"apns-push-type: {$type}",
"apns-priority: 5",
);
// open connection
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0,
CURLOPT_URL => $url,
CURLOPT_PORT => 443,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $message,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSLCERT => $cert,
CURLOPT_HEADER => 1,
CURLOPT_RETURNTRANSFER =>true
));
$result = curl_exec($ch);
if ($result === FALSE) {
$error = curl_error($ch);
echo "curl faild: $error";
curl_close($ch);
return false;
}
// get response
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($status == "200")
echo "OK";
else
echo "FAIL: $status";
return false;
}