urbanairship / react-native-airship

Airship React Native module
Other
88 stars 62 forks source link

Channel Id never gets generated #577

Closed maya-salcedo closed 4 months ago

maya-salcedo commented 4 months ago

❗For how-to inquiries involving Airship functionality or use cases, please contact (support)[https://support.airship.com/].

Preliminary Info

What Airship dependencies are you using?

"@ua/react-native-airship": "19.0.0",

What are the versions of any relevant development tools you are using?

 "react": "18.2.0",
 "react-native": "0.73.4", --> fabric architecture enabled
 "node": ">=20"

Report

What unexpected behavior are you seeing?

On iOS, calling takeOff on the App.tsx file with the app secret and keys in the config never generates channel Id.

await Airship.takeOff({
                enabledFeatures: [],
                default: {
                  appSecret: 'myapp_appSecret',
                  appKey: 'myapp_appKey',
                },
                site: 'eu',
                urlAllowList: ['*'],
              });

Turn on push notification feature,

            await Airship.push.setUserNotificationsEnabled(true);
            await Airship.privacyManager.setEnabledFeatures([Feature.Push]);

I have waited at least 10 minutes or more, but this listener never got triggered.

    Airship.addListener(EventType.ChannelCreated, (event) => {
      console.log('ChannelCreated:', JSON.stringify(event));
    });

or even fetching it after registration token is created, await Airship.channel.getChannelId(); endpoint returns undefined.

What is the expected behavior?

Channel Id should be available, not immediately, but should be available later at least.

What are the steps to reproduce the unexpected behavior?

Do you have logging for the issue?

[E] AirshipKit/Config.swift validate(logIssues:) [Line 617] Current App Key  is not valid.
[E] AirshipKit/Config.swift validate(logIssues:) [Line 624] Current App Secret  is not valid.
…
Running "myapp" with {"rootTag":1,"initialProps":{"concurrentRoot":true},"fabric":true}
…
[E] AirshipKit/Config.swift validate(logIssues:) [Line 617] Current App Key  is not valid.
[E] AirshipKit/Config.swift validate(logIssues:) [Line 624] Current App Secret  is not valid.
…
[I] AirshipKit/Airship.swift commonTakeOff(_:onReady:) [Line 315] Airship TakeOff! SDK Version 18.5.0, App Key: myapp_appKey, inProduction: false
[V] AirshipKit/Channel.swift isRegistrationAllowed [Line 388] Skipping channel create. All features are disabled.
[V] AirshipKit/ContactManager.swift enqueueTask() [Line 300] Channel not created, unable to enqueue task
[D] AirshipKit/ModuleLoader.swift loadModules(_:) [Line 98] Loading module messageCenter
[D] AirshipKit/ModuleLoader.swift loadModules(_:) [Line 98] Loading module preferenceCenter
[I] AirshipKit/PreferenceCenter.swift init(dataStore:privacyManager:remoteData:) [Line 93] PreferenceCenter initialized
[D] AirshipKit/ModuleLoader.swift loadModules(_:) [Line 98] Loading module featureFlags
[D] AirshipKit/ModuleLoader.swift loadModules(_:) [Line 98] Loading module automation
[V] AirshipKit/ContactManager.swift enqueueTask() [Line 300] Channel not created, unable to enqueue 
[I] AirshipKit/DefaultAppIntegrationDelegate.swift didRegisterForRemoteNotifications(deviceToken:) [Line 30] Application registered device token: *********************************************601ab
[I] AirshipKit/Push.swift didRegisterForRemoteNotifications(_:) [Line 1033] Device token string: *********************************************601ab
[I] AirshipKit/Push.swift deviceToken [Line 362] Device token: *********************************************601ab
[V] AirshipKit/Analytics.swift recordEvent(_:feedEvent:date:sessionID:) [Line 386] Analytics disabled, ignoring event: deviceRegistration
'PushNotificationStatusChangedStatus:', '{"status":{"isUserOptedIn":false,"isPushTokenRegistered":true,"isUserNotificationsEnabled":true,"isPushPrivacyFeatureEnabled":true,"isOptedIn":false,"areNotificationsAllowed":false}}'
[D] AirshipKit/UNNotificationRegistrar.swift updateRegistration(options:skipIfEphemeral:) [Line 50] requestAuthorizationWithOptions true
[V] AirshipKit/Push.swift updateAuthorizedNotificationTypes(alwaysUpdateChannel:) [Line 533] Updating authorized types.
'IOSAuthorizedNotificationSettingsChanged:', '{"authorizedSettings":["lock_screen","alert","notification_center","sound","badge"]}'
{ registrationToken: '*********************************************601ab' }
[D] AirshipKit/UNNotificationRegistrar.swift updateRegistration(options:skipIfEphemeral:) [Line 50] requestAuthorizationWithOptions true
{ channelId: undefined }
…
'PushNotificationStatusChangedStatus:', '{"status":{"isUserOptedIn":true,"isPushTokenRegistered":true,"isUserNotificationsEnabled":true,"isPushPrivacyFeatureEnabled":true,"isOptedIn":true,"areNotificationsAllowed":true}}'
[D] AirshipKit/SessionTracker.swift didBecomeActiveNotification() [Line 120] Application did become active.
[V] AirshipKit/Push.swift updateAuthorizedNotificationTypes(alwaysUpdateChannel:) [Line 533] Updating authorized types.
[V] AirshipKit/WorkBackgroundTasks.swift beginTask(_:expirationHandler:) [Line 35] Requesting task: Airship: Airship.MessageCenterInbox#update(0)
[V] AirshipKit/WorkBackgroundTasks.swift beginTask(_:expirationHandler:) [Line 60] Task granted: Airship: Airship.MessageCenterInbox#update(0)
[V] AirshipKit/Worker.swift process(pendingRequest:attempt:onCancel:) [Line 160] Work Airship.MessageCenterInbox#update(0) finished
…
D] AirshipKit/RemoteDataAPIClient.swift fetchRemoteData(url:auth:lastModified:remoteDataInfoBlock:) [Line 65] Fetching remote data finished with response: <NSHTTPURLResponse: 0x3006712c0> { URL: https://remote-data.asnapieu.com/api/remote-data/app/myapp_appKey/ios?language=en&country=FI&sdk_version=18.5.0&random_value=4657 } { Status Code: 401, Headers {
    "Alt-Svc" =     (
        "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"
    );
    "Content-Length" =     (
        54
    );
    "Content-Type" =     (
        "application/json"
    );
    Date =     (
        "Wed, 17 Jul 2024 08:19:22 GMT"
    );
    Via =     (
        "1.1 google"
    );
} }
[V] AirshipKit/RemoteDataProvider.swift refresh(changeToken:locale:randomeValue:) [Line 187] Refresh result for app remote data: AirshipHTTPResponse<RemoteDataResult>(result: nil, statusCode: 401, headers: ["Via": "1.1 google", "Date": "Wed, 17 Jul 2024 08:19:22 GMT", "Alt-Svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000", "Content-Length": "54", "Content-Type": "application/json"])
[V] AirshipKit/Worker.swift process(pendingRequest:attempt:onCancel:) [Line 164] Work RemoteData.refresh(1) failed
[V] AirshipKit/Worker.swift process(pendingRequest:attempt:onCancel:) [Line 172] Work RemoteData.refresh(1) backing off for 90.0 seconds.
....

[V] AirshipKit/WorkBackgroundTasks.swift beginTask(_:expirationHandler:) [Line 60] Task granted: Airship: RemoteData.refresh(1)
[V] AirshipKit/RemoteDataProvider.swift refresh(changeToken:locale:randomeValue:) [Line 148] Checking contact remote data
[V] AirshipKit/RemoteDataProvider.swift refresh(changeToken:locale:randomeValue:) [Line 148] Checking app remote data
[V] AirshipKit/RemoteDataProvider.swift refresh(changeToken:locale:randomeValue:) [Line 178] Requesting app remote data
[D] AirshipKit/RemoteDataAPIClient.swift fetchRemoteData(url:auth:lastModified:remoteDataInfoBlock:) [Line 61] Request to update remote data: AirshipRequest(url: Optional(https://remote-data.asnapieu.com/api/remote-data/app/myapp_appKey/ios?language=en&country=FI&sdk_version=18.5.0&random_value=4657), headers: ["Accept": "application/vnd.urbanairship+json; version=3;", "X-UA-Appkey": "myapp_appKey"], method: Optional("GET"), auth: Optional(AirshipKit.AirshipRequestAuth.generatedAppToken), body: nil, compressBody: false)
[D] AirshipKit/RemoteDataAPIClient.swift fetchRemoteData(url:auth:lastModified:remoteDataInfoBlock:) [Line 65] Fetching remote data finished with response: <NSHTTPURLResponse: 0x300689240> { URL: https://remote-data.asnapieu.com/api/remote-data/app/myapp_appKey/ios?language=en&country=FI&sdk_version=18.5.0&random_value=4657 } { Status Code: 401, Headers {
    "Alt-Svc" =     (
        "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"
    );
    "Content-Length" =     (
        54
    );
    "Content-Type" =     (
        "application/json"
    );
    Date =     (
        "Wed, 17 Jul 2024 08:32:56 GMT"
    );
    Via =     (
        "1.1 google"
    );
} }
[V] AirshipKit/RemoteDataProvider.swift refresh(changeToken:locale:randomeValue:) [Line 187] Refresh result for app remote data: AirshipHTTPResponse<RemoteDataResult>(result: nil, statusCode: 401, headers: ["Date": "Wed, 17 Jul 2024 08:32:56 GMT", "Via": "1.1 google", "Alt-Svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000", "Content-Type": "application/json", "Content-Length": "54"])
[V] AirshipKit/Worker.swift process(pendingRequest:attempt:onCancel:) [Line 164] Work RemoteData.refresh(1) failed
[V] AirshipKit/Worker.swift process(pendingRequest:attempt:onCancel:) [Line 172] Work RemoteData.refresh(1) backing off for 120.0 seconds.
Apekka commented 4 months ago

Hello, could you send logs while using your correct App Key please? It would help, thanks Otherwise the first error displayed is the request to get a channel ID being unauthorized

maya-salcedo commented 4 months ago

Hello @Apekka, I used my correct App Key when getting the logs. I just replaced it with "myapp_appKey" placeholder in here so I don't have to share it publicly here.

Apekka commented 4 months ago

@maya-salcedo Thank you for the heads up.
Sadly I couldn't replicate your issue, the 401 API Error is caused by your appKey/appSecret being incorrect or missing, could you double check if they match please?

maya-salcedo commented 4 months ago

@Apekka Yes I checked several times that my appKey and AppSecret are correct. If I deliberately initialize the Airship using a random string for appKey:

await Airship.takeOff({
        enabledFeatures: [],
        development: {
          appKey: 'this-is-a-random-number',
          appSecret: 'myapp_appSecret',
          logLevel: 'verbose',

          ios: {
            logPrivacyLevel: 'public',
          },
        },
        site: 'eu',
        urlAllowList: ['*'],
      });

This is the log that I get

[E] AirshipKit/Config.swift validate(logIssues:) [Line 617] Current App Key  is not valid.
[E] AirshipKit/Config.swift validate(logIssues:) [Line 624] Current App Secret  is not valid.
.....
[E] AirshipKit/Config.swift validate(logIssues:) [Line 617] Current App Key this-is-a-random-number is not valid.

Similar logs for a deliberately wrong app secret value

await Airship.takeOff({
        enabledFeatures: [],
        development: {
          appKey: 'myapp_appKey',
          appSecret: 'random-string-for-app-secret',
          logLevel: 'verbose',

          ios: {
            logPrivacyLevel: 'public',
          },
        },
        site: 'eu',
        urlAllowList: ['*'],
      });

The log:

 [E] AirshipKit/Config.swift validate(logIssues:) [Line 617] Current App Key  is not valid.
[E] AirshipKit/Config.swift validate(logIssues:) [Line 624] Current App Secret  is not valid.
...
[E] AirshipKit/Config.swift validate(logIssues:) [Line 624] Current App Secret random-string-for-app-secret is not valid.

The SDK would not be initialised at all if I have incorrect app secret or app key values. I would not get a registration token at all.

rlepinski commented 4 months ago

That check is just checking the shape of the app key and secret. Sometimes customers use the master secret instead of the app secret. The other thing is to make sure the site is correct, if you are using https://go.airship.eu/ its eu, if not its us.

The last thing to note here is it may take an additional app run to switch config, so make sure you run it twice or a new install when modifying the config.

maya-salcedo commented 4 months ago

Thanks a lot @rlepinski! It is indeed the wrong config value for the site. The channel id is now available after switching to site: 'us'.

rlepinski commented 4 months ago

Glad its working :)