Skip to content
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

MessagingCore.getInstance().getCurrentToken() throws selector error on iOS #123

Closed
fleminze opened this issue Aug 29, 2022 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@fleminze
Copy link

This is happening with version 2.2.9

-[__NSCFString bytes]: unrecognized selector sent to instance 0x2812977e0. I think it is breaking in the first line of APNSTokenToString in firebase-messaging-core/platforms/ios/src/NSCFirebaseMessagingCore.m, but I'm not sure how to fix it.

@redneo12
Copy link

Bump

my code:


const messageCore = await MessagingCore.getInstance()
const defaultApp = await firebase().initializeApp();

const iosParams = {
    ios: {
        alert: true,
        announcement: true,
        badge: true
    }
};
const androidParams = { android: {} };
const requestedParams: any = isIOS ? iosParams : androidParams;
if (isAndroid) {
    //android 33 cant getPermissions properly; if Android 33 bypass permission
    if (android.os.Build.VERSION.SDK_INT >= 33) {
        firebase().messaging().requestPermission(requestedParams).then((authorizationStatus: AuthorizationStatus) => {
            firebase().messaging().registerDeviceForRemoteMessages();
        }).catch((reason: any) => {
            console.log("firebase permission request failed");
        });
        console.log('Authorization status:... ');
    }
}



if (isIOS) {
    const authStatus = await MessagingCore.getInstance().requestPermission(requestedParams);

    const enabled = authStatus === AuthorizationStatus.AUTHORIZED || authStatus === AuthorizationStatus.PROVISIONAL;

    if (enabled) {
        console.log('Authorization status:', authStatus);

        const didRegister = messageCore.registerDeviceForRemoteMessages();
        console.log('didRegister:', JSON.stringify(didRegister));
    }

}

messageCore.addOnMessage(async (remoteMessage) => {
    // alert('A new Push message arrived!\n' + JSON.stringify(remoteMessage));
    NotificationService.saveLocalNotificationData(remoteMessage.data.JobPilotId, remoteMessage.data.JobNumber, remoteMessage.data.Action)

    Dialogs.confirm({
        title: remoteMessage.title,
        message: remoteMessage.body,
        okButtonText: "Okay"
    }).then(r => {
        if (r == true) {
            if (remoteMessage.data.Action.includes('Un-Dispatched')) {
                this.eSourceNotifications.removeFromJob(remoteMessage.data.Action.JobNumber);
            }

        }
    });
});
messageCore.showNotificationsWhenInForeground = true;



messageCore
    .getCurrentToken()
    .then((token) => {
        console.log("in getCurrentToken: " + token)
        this.saveUserToken(token);
    });
messageCore.addOnToken((token) => {
    console.log("in addOnToken: " + token)
    this.saveUserToken(token);
});
firebase().inAppMessaging().isMessagesDisplaySuppressed = false;
console.log("Done! innit")
 

Error Message from messageCore.getCurrentToken()

ERROR Error: Uncaught (in promise): Error: No token found Error: No token found at file: src/webpack:/portlink-mobile/node_modules/@nativescript/firebase-messaging-core/index.ios.js:110:0 at new ZoneAwarePromise (file: src/webpack:/portlink-mobile/node_modules/zone.js/fesm2015/zone.js:1427:0) at MessagingCore.getCurrentToken (file: src/webpack:/portlink-mobile/node_modules/@nativescript/firebase-messaging-core/index.ios.js:104:0) at file: src/webpack:/portlink-mobile/src/app/services/notification/notification.service.ts:98:13 at Generator.next (<anonymous>) at asyncGeneratorStep (file: src/webpack:/portlink-mobile/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:3:0) at _next (file: src/webpack:/portlink-mobile/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:25:0) at _ZoneDelegate.invoke (file: src/webpack:/portlink-mobile/node_modules/zone.js/fesm2015/zone.js:372:0) at Object.onInvoke (file: src/webpack:/portlink-mobile/node_modules/@angular/core/fesm2015/core.mjs:26267:0) at _ZoneDelegate.invoke (file: src/webpack:/portlink-mobile/node_modules/zone.js/fesm2015/zone.js:371:0)
Best Part, messageCore.addOnToken returns a Token in the console
in addOnToken: B7D9F363BA8CA28AD999650AFC0552A2EFAE644A72F5ACD38B07EF55EF4AFFA7

but whenever i pass it in a FirebaseMessage POST, i get this error

"error": { "code": 400, "message": "The registration token is not a valid FCM registration token", "status": "INVALID_ARGUMENT", "details": [ { "@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError", "errorCode": "INVALID_ARGUMENT" } ] }

@triniwiz triniwiz added the bug Something isn't working label Sep 21, 2022
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