Troubleshooting Push Notifications

Check push notification status and fix common issues.

View as Markdown

If push notifications aren’t working as expected, you can check the notification status to diagnose the issue. The SDK provides detailed information about their current state.

Get Current Notification Status

Read the current notification status from Airship.push.notificationStatus to inspect each field:

Check notification status

let status = await Airship.push.notificationStatus

print("User notifications enabled: \(status.isUserNotificationsEnabled)")
print("Notifications allowed: \(status.areNotificationsAllowed)")
print("Privacy feature enabled: \(status.isPushPrivacyFeatureEnabled)")
print("Push token registered: \(status.isPushTokenRegistered)")
print("User opted in: \(status.isUserOptedIn)")
print("Fully opted in: \(status.isOptedIn)")
print("Display status: \(status.displayNotificationStatus)")
@import AirshipObjectiveC;

[UAirship.push getNotificationStatusWithCompletionHandler:^(UAPushNotificationStatus *status) {
    NSLog(@"User notifications enabled: %d", status.isUserNotificationsEnabled);
    NSLog(@"Notifications allowed: %d", status.areNotificationsAllowed);
    NSLog(@"Privacy feature enabled: %d", status.isPushPrivacyFeatureEnabled);
    NSLog(@"Push token registered: %d", status.isPushTokenRegistered);
    NSLog(@"User opted in: %d", status.isUserOptedIn);
    NSLog(@"Fully opted in: %d", status.isOptedIn);
}];

Listen for Status Changes

Use the following to monitor notification status changes in real time:

Monitor notification status

Task {
    for await status in await Airship.push.notificationStatusUpdates {
        print("Notification status changed:")
        print("User opted in: \(status.isUserOptedIn)")
        print("Fully opted in: \(status.isOptedIn)")
    }
}
Note

The status stream itself is not available in Objective-C. Implement UARegistrationDelegate and re-fetch the status from notificationAuthorizedSettingsDidChange: instead.

@import AirshipObjectiveC;

@interface MyRegistrationDelegate : NSObject <UARegistrationDelegate>
@end

@implementation MyRegistrationDelegate

- (void)notificationAuthorizedSettingsDidChange:(UAAuthorizedNotificationSettings *)authorizedSettings {
    [UAirship.push getNotificationStatusWithCompletionHandler:^(UAPushNotificationStatus *status) {
        NSLog(@"Notification status changed:");
        NSLog(@"User opted in: %d", status.isUserOptedIn);
        NSLog(@"Fully opted in: %d", status.isOptedIn);
    }];
}

@end

UAirship.push.registrationDelegate = [[MyRegistrationDelegate alloc] init];

Get the Device Token

isPushTokenRegistered only tells you whether a token exists. To see the actual APNs device token, or to know the moment registration succeeds or fails, read deviceToken or implement registrationDelegate.

Get the device token

let token = Airship.push.deviceToken
@import AirshipObjectiveC;

NSString *token = UAirship.push.deviceToken;

To be notified when registration succeeds or fails, implement a registration delegate:

Listen for registration events

class MyRegistrationDelegate: RegistrationDelegate {
    func apnsRegistrationSucceeded(withDeviceToken deviceToken: Data) {
        // Handle successful registration
    }

    func apnsRegistrationFailedWithError(_ error: any Error) {
        // Handle registration failure
    }
}

Airship.push.registrationDelegate = MyRegistrationDelegate()
@import AirshipObjectiveC;

@interface MyRegistrationDelegate : NSObject <UARegistrationDelegate>
@end

@implementation MyRegistrationDelegate

- (void)apnsRegistrationSucceededWithDeviceToken:(NSData *)deviceToken {
    // Handle successful registration
}

- (void)apnsRegistrationFailedWithError:(NSError *)error {
    // Handle registration failure
}

@end

UAirship.push.registrationDelegate = [[MyRegistrationDelegate alloc] init];

Understanding Notification Status Fields

The AirshipNotificationStatus struct provides detailed information about why push might not be working:

FieldDescription
isUserNotificationsEnabledWhether Airship.push.userPushNotificationsEnabled is set to true
areNotificationsAllowedWhether the user has granted notification permissions (at least one authorized type)
isPushPrivacyFeatureEnabledWhether the push privacy feature is enabled in AirshipPrivacyManager
isPushTokenRegisteredWhether a push token has been successfully registered with the system
displayNotificationStatusThe system permission status (.granted, .denied, .notDetermined, .ephemeral)
isUserOptedIntrue if user notifications are enabled, privacy feature is enabled, notifications are allowed, and display status is granted
isOptedIntrue if isUserOptedIn is true AND a push token is registered

Common Status Scenarios

Status: isUserNotificationsEnabled = false

  • Cause: Airship.push.userPushNotificationsEnabled has not been set to true.
  • Solution: Enable user notifications in your app code.

Status: areNotificationsAllowed = false

  • Cause: User denied notification permissions or permissions not yet requested.
  • Solution: Request notification permissions or guide user to system settings.

Status: isPushPrivacyFeatureEnabled = false

  • Cause: Push privacy feature is disabled in Privacy Manager.
  • Solution: Enable the push privacy feature: Airship.privacyManager.enabledFeatures = [.push].

Status: isPushTokenRegistered = false

  • Cause: Device hasn’t received a push token from APNs yet.
  • Solution: Check network connectivity, APNs certificate configuration, and device/simulator limitations.

Status: isUserOptedIn = true but isOptedIn = false

  • Cause: Push token registration is pending or failed.
  • Solution: Check console logs for APNs registration errors, verify network connectivity, and ensure proper entitlements.