Support

How do I troubleshoot issues with Push Notifications on iOS?

If you are having trouble with Push, the first place you should check is the Logs in the dashboard.  It will show you if a device was properly registered for pushes and if/when a push was successfully sent:

Here are a few reasons why you might not be receiving push notifications on iOS. 

1. Your app ID is incorrect

Make sure the app ID you've uploaded your p12 file in the dashboard matches the one in you XCode project.  If you switch to the production, you will need to change the app id in XCode and re-upload your push certs.

2. The certificate is invalid

To test your push certificate, we recommend using a third party tool like
Houston or APNS Tester to send pushes to the device. If the pushes don't work with the third party then you'll need to re-create your certs.

Here's an example of a push using Houston:

apn push "<5e8f5cc0 be283f88 cc4ebb7d b6091499 80f51631 5ebf4928 b59a2a62 198d20d0>" -c -out "apple_push_notification.pem" -m "Hello from the command line!" 

We recommend that you upload development cert, production, and any ad-hoc certs.  Layer will automatically determine which cert to use. 

NOTE: If you switch from using a Layer Staging ID to a Layer Production ID you will need to re-upload all your certs.

3. Your device is not correctly registered for push notifications

Here are 2 common mistakes people make in their code:
1. Make sure you are registering for Push Notifications on app launch. This can be done by placing this code inside didFinishLaunchingWithOptions:

// Checking if app is running iOS 8
if ([application respondsToSelector:@selector(registerForRemoteNotifications)]) {
// Register device for iOS8
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[application registerUserNotificationSettings:notificationSettings];
[application registerForRemoteNotifications];
} else {
// Register device for iOS7
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge];
}

2. Make sure you are correctly calling [layerClient updateRemoteNotificationDeviceToken...]

We recommend calling inside didRegisterForRemoteNotificationsWithDeviceToken to send Layer the device token. Without the device token we don't know which device to send pushes to. If the third party tool above works but Layer push does not work then the cause is mostly likely related to device tokens not being sent to Layer.

For more information about push integration, check out our Push Integration docs.

TIP: You can also check to see if the app is failing to register by implementing didFailToRegisterForRemoteNotificationsWithError. If you look at the error you should be able to figure out why you're not seeing pushes.

- (void) application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"PUSH ERROR: %@", error);
}

TIP #2: The updateRemoteNotificationDeviceToken will only work if you're connected to Layer. So if you're calling `updateRemoteNotificationDeviceToken` but you're not seeing a message "Push: registered apns device..." in the logs you are probably not connected to Layer. The easiest way to fix this is to move the connectWithCompletion call to inside `didFinishLaunchingWithOptions`. If the client isn’t authenticated we won’t push up the token, but we will still store it. When the client authenticates and starts messaging services then the Layer SDK pushes the stored token up again.

4. There's a problem with your provisioning profile or your XCode project is using the wrong profile/certificate.

Here are 2 common mistakes people make in their XCode projects:

1. Make sure your provisioning profiles are up-to-date. The device info is store in the certificates so any time you add a new device to the profile you will need to re-create the profile and certificates.

2. Make sure that your XCode Project Settings is pointing the correct Certificate and Provisioning profile:

 

For more information about Apple's push notification steps, check out our Push Notification docs.

5. You're not setting LYRMessageOptionsPushNotificationAlertKey when sending the message

You configure what you want the push text to be when you send a message by seeing the LYRMessagePushNotificationAlertMessageKey option.  Here's example code:

NSString *messageText = @"Hi how are you?"
LYRMessagePart *part = [LYRMessagePart messagePartWithText:messageText];
// Configure the push notification text to be the same as the message text
LYRMessage *message = [layerClient newMessageWithParts:@[part] options:@{LYRMessagePushNotificationAlertMessageKey: messageText} error:nil];

6. Your .p12 is missing the certificate or the key

When inside the Keychain Access app make sure you are exporting the key and the certificate:

7. You are using silent notifications and the phone is unplugged

We currently recommend that developers do not rely on silent notifications. We’ve done extensive testing on silent notifications internally with various combinations of sound, alert, and content-available flags and the net outcome is that there is no way to guarantee that iOS will wake the app up in response to a push notification. We believe this is because of how iOS handles power management. For example: if you plug the device into a power source it will get woken up on every push. When its not plugged in we've perceived that whether or not the app will be awakened is unpredictable.

If you want reliable, immediate delivery of push notifications we recommend utilizing the LYRMessagePushNotificationAlertMessageKey option to set Alert text and to use the "Show unread in badges" feature in the dashboard. If you try to use silent notifications and emit local notifications then you will always be subject to latency and a variable amount of batching. Unfortunately, the behavior is out of our control at this time.

If pushes worked and then you stopped receiving pushes but haven't made any changes on your end, please check our Status page for any outages. If nothing is listed, please submit a support request.

8. You are using TestFlight to distribute builds but you haven't uploaded Production Push Certs to Layer.

TestFlight builds act similar to production builds, and they do not work with development push certificates. You need to create a  App Store Distribution profile and Production Push Cert in the Apple Developer Portal for TestFlight AND you must upload them to Layer (Both Layer Staging and Production app id's do accept Apple Production Push certs).

---

NOTE: The simulator is incapable of receiving push notifications. You can send mock playloads to a simulator using SimulatorRemoteNotifications for testing purposes.

Have more questions? Submit a request