urbanairship / ios-library

Urban Airship iOS SDK
http://urbanairship.com
Apache License 2.0
478 stars 265 forks source link

No push notifications after project change #393

Closed r3econ closed 6 months ago

r3econ commented 6 months ago

Preliminary Info

What Airship dependencies are you using?

iOS SDK 17.6.1 and 17.8.0

Report

What unexpected behavior are you seeing?

We are facing a strange issue in our iOS app. App version that we had in AppStore contained SDK version 17.6.1. We shipped an update with version 17.8.0 that also included a change of Airship project (new app key and secret). What we are experiencing

Does anyone know why the first group of users do not receive push notificaitons?

What is the expected behavior?

Users receive push notifications

rlepinski commented 6 months ago

All settings on the SDK are stored under the app key. If you enabled push on the old, but not the new but only for new installs then you might end up in a state where the upgrade path would have push disabled, but new install path would have it enabled.

What is the difference between your app flow for a new install vs an upgrade? Can you identify one of those channels that is not able to receive push and check the opt-in status?

r3econ commented 6 months ago

@rlepinski thanks for the answer!

The users that allowed push notifications in the old app version and then updated it, can't currently receive push notifications. The Airship app key and secrets were changed during the update, push notification setting remained the same - allowed. I'd assume the pushes should still work since iPhone settings show that the permission was given and is active.

In such scenario, the users that updated are marked with Opted-Out tag in the dashboard:

image

On the other hand, before, updating the app version without a change in Airship app key and secret has never rendered users unable to receive push notifications. Do you know if there is any way to fix this?

We are considering shipping a version that would use the old Airship project configuration, so going back to the old configuration (app key/secret) as this looks like the only way to get it to work again

rlepinski commented 6 months ago

@r3econ Airship has its own push enabled flag that when enabled, we prompt for push. This allows you to disable Airship without disabling it for the app. The opt-in status on the page above basically equates to this:

let isOptIn = Airship.push.userPushNotificationsEnabled  && areNotificationsAllowed

The app still has permission if it had it before, but the userPushNotificationsEnabled is no longer enabled since the default case is to be disabled on a fresh install. Since this is a new app key then we treat it like a fresh install.

I think you have a couple of ways to fix this. The easiest way is just to enable push on Airship if you have the permission to receive push. You can do this after takeOff:

        Task {
            let status = await Airship.push.notificationStatus
            if status.areNotificationsAllowed, !status.isUserNotificationsEnabled {
                Airship.push.userPushNotificationsEnabled = true
            }
        }

If you have your own flag and know if you already prompted for push, you can just use that and enable push on Airship:

   Airship.push.userPushNotificationsEnabled = true

The reason why you don't just want to enable push on Airship is it will prompt for permission at that point. Most apps want to prompt the user at a later time and not when the app first opens.

You can also put airship into a passive mode for APNS, but if you do that you need to register for user notifications directly with UserNotifiictionCenter and register our categories. Its a bit more work but gives your app full control. To do that:

       ...
        config.requestAuthorizationToUseNotifications = false
        Airship.takeOff(config, launchOptions: launchOptions)
        Airship.push.userPushNotificationsEnabled = true

Then when you register categories you need to use Airship's as well (assuming you want those):

let categories = Airship.push.combinedCategories + myCategories
UNUserNotificationCenter.current().setNotificationCategories(categories)

I would not recommend the passive mode thing as its more work and you have more things to test. If you do decide to do that, you can still trigger notification opt-in through Airship in-app messaging but you need to also a AirshipPermissionDelegate for notifications:

Airship.permissionsManager.setDelegate(notificationPermissionDelegate, permission: .displayNotifications)
r3econ commented 6 months ago

@rlepinski thanks a lot for the hints, I really appreciate. I'll check it out and report back!

h0shy commented 6 months ago

The first answer fixed it, thanks a lot @rlepinski.

r3econ commented 6 months ago

@rlepinski it works! Thanks for all the hints and explanations 😃