Skip to content

[firebase-messaging][ios] - TNSFirebaseMessaging is not defined #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
VepretskiyD opened this issue Aug 3, 2022 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@VepretskiyD
Copy link

iOS 15.5 (both simulator and device)

"@nativescript/core": "~8.3.1",
"@nativescript/ios": "~8.3.2",
"@nativescript/firebase-core": "^2.2.6",
"@nativescript/firebase-crashlytics": "^2.2.6",
"@nativescript/firebase-dynamic-links": "^2.2.6",
"@nativescript/firebase-messaging": "^2.2.6",

          const messaging = firebase().messaging()
          messaging
            .requestPermission({
              ios: {
                alert: true,
              },
            })
            .then(() => {
              messaging.registerDeviceForRemoteMessages()
              messaging.showNotificationsWhenInForeground = true
            })

messaging.showNotificationsWhenInForeground get or set throws an error TNSFirebaseMessaging is not defined

@triniwiz
Copy link
Member

triniwiz commented Aug 3, 2022

try npm i @nativescript/firebase-messaging-core for now as this shouldn't be required

@triniwiz triniwiz added the bug Something isn't working label Aug 3, 2022
@VepretskiyD
Copy link
Author

VepretskiyD commented Aug 3, 2022

@triniwiz , I switched to messaging-core and now I can get/set the showNotificationsWhenInForeground but it causes other issues:

  • on iOS simulator getCurrentToken always returns no token found
  • on a real device it returns an APNS token but I need a regular device token, which means no push notifications at all
    getCurrentToken() {
        return new Promise((resolve, reject) => {
            if (!TNSFirebaseCore.isSimulator() && !UIApplication.sharedApplication.registeredForRemoteNotifications) {
                reject(new Error('You must be registered for remote messages before calling getToken, see MessagingCore.getInstance().registerDeviceForRemoteMessages()'));
                return;
            }
            if (!__classPrivateFieldGet(this, _MessagingCore_APNSToken, "f")) {
                reject(new Error('No token found'));
                return;
            }
            resolve(this.getAPNSToken());
        });
    }
    

@VepretskiyD
Copy link
Author

VepretskiyD commented Aug 3, 2022

          const messaging = MessagingCore.getInstance()
          messaging.showNotificationsWhenInForeground = true
          messaging
            .requestPermission({
              ios: {
                alert: true,
              },
            })
            .then(async () => {
                await messaging.registerDeviceForRemoteMessages()
               messaging
                .getCurrentToken()
                .then(token => {
                  // 
                })
                .catch((e) => {
                  // throws 'no token found'
                })
              messaging.addOnToken(token => {
                // return APNS token
              })
             });

@lekhmanrus
Copy link

I'm experiencing the same issue - #106 is related to this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants