Troubleshooting Push Notification
Estimated reading time: 9 minutesIf you are facing issues with Push Notification, go through this section without skipping any details. We have covered all scenarios and even provided you with scripts to bypass mesibo and send push directly.
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 console.
- 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.
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 Execution. Also, according to these threads (here, here, and here), 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
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';
$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;
}
Troubleshooting using Webhooks
If your app cannot receive push notifications, even after troubleshooting with the steps above, you can also debug the issue with push notifications using webhooks.
You can inspect the push request and response, which can be made available to you through webhooks. To do this, check Notify failed push notifications while setting up Webhook, in the console. When a push notification fails, you will receive a webhook request( a POST
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.
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 |