NativeScript / push-plugin

Contains the source code for the Push Plugin.
Apache License 2.0
123 stars 45 forks source link

iOS crashes before registering device #236

Closed lumayara closed 6 years ago

lumayara commented 6 years ago

I am trying now to make the notifications work with Firebase and keep getting this error:

***** Fatal JavaScript exception - application has been terminated. *****
Native stack trace:
1   0x1008bc649 NativeScript::reportFatalErrorBeforeShutdown(JSC::ExecState*, JSC::Exception*, bool)
2   0x1008ef860 -[TNSRuntime executeModule:referredBy:]
3   0x1002ff6c1 main
4   0x1067ac955 start
JavaScript stack trace:
1   _init@file:///app/tns_modules/nativescript-push-notifications/push-plugin.js:23:52
2   register@file:///app/tns_modules/nativescript-push-notifications/push-plugin.js:59:10
3   anonymous@file:///app/main.js:40:20
4   evaluate@[native code]
5   moduleEvaluation@[native code]
6   @[native code]
7   promiseReactionJob@[native code]
JavaScript error:
file:///app/tns_modules/nativescript-push-notifications/push-plugin.js:23:52: JS ERROR TypeError: undefined is not an object (evaluating 'settings.notificationCallbackIOS')
***** Fatal JavaScript exception - application has been terminated. *****
Native stack trace:
1   0x105acd649 NativeScript::reportFatalErrorBeforeShutdown(JSC::ExecState*, JSC::Exception*, bool)
2   0x105b00860 -[TNSRuntime executeModule:referredBy:]
3   0x1055106c1 main
4   0x107fc4955 start
JavaScript stack trace:
1   _init@file:///app/tns_modules/nativescript-push-notifications/push-plugin.js:23:52
2   register@file:///app/tns_modules/nativescript-push-notifications/push-plugin.js:59:10
3   anonymous@file:///app/main.js:40:20
4   evaluate@[native code]
5   moduleEvaluation@[native code]
6   @[native code]
7   promiseReactionJob@[native code]
JavaScript error:
file:///app/tns_modules/nativescript-push-notifications/push-plugin.js:23:52: JS ERROR TypeError: undefined is not an object (evaluating 'settings.notificationCallbackIOS')

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

CLI: 4.1.1 Cross-platform modules: 3.4.1 Runtime(s): tns-ios: 4.1.1, tns-android: 4.1.3 Plugin(s): "dependencies": { "@angular/animations": "~5.2.0", "@angular/common": "~5.2.0", "@angular/compiler": "~5.2.0", "@angular/core": "~5.2.0", "@angular/forms": "~5.2.0", "@angular/http": "~5.2.0", "@angular/platform-browser": "~5.2.0", "@angular/platform-browser-dynamic": "~5.2.0", "@angular/router": "~5.2.0", "email-validator": "^1.1.1", "nativescript-angular": "~5.2.0", "nativescript-iqkeyboardmanager": "^1.3.0", "nativescript-modal-datetimepicker": "^1.1.3", "nativescript-oauth": "^2.1.2", "nativescript-platform-css": "^1.6.5", "nativescript-push-notifications": "^1.1.4", "nativescript-theme-core": "~1.0.4", "nativescript-ui-dataform": "^3.5.0", "nativescript-ui-listview": "^3.5.2", "nodeify": "^1.0.1", "reflect-metadata": "~0.1.8", "rxjs": "~5.5.0", "tns-core-modules": "^3.4.1", "zone.js": "~0.8.4" }, "devDependencies": { "babel-traverse": "6.4.5", "babel-types": "6.4.5", "babylon": "6.4.5", "css-font-family": "^1.0.7", "lazy": "1.0.11", "nativescript-dev-typescript": "~0.6.0", "typescript": "~2.6.2" } In my main.ts I have:

//code before
var pushSettings = {
    // Android settings
    senderID: "783478347898", // this is a random id, I have the real one in my code
    notificationCallbackAndroid: (stringifiedData: String, fcmNotification: any) => {
        const notificationBody = fcmNotification && fcmNotification.getBody();
        this.updateMessage("Message received!\n" + notificationBody + "\n" + stringifiedData);
    },

    // iOS settings
    badge: true, // Enable setting badge through Push Notification
    sound: true, // Enable playing a sound
    alert: true, // Enable creating a alert
    notificationCallbackIOS: (message: any) => {
        this.updateMessage("Message received!\n" + JSON.stringify(message));
    }
};

pushPlugin.register(this.pushSettings, (token: String) => {
    this.updateMessage("Device registered. Access token: " + token);
    // token displayed in console for easier copying and debugging durng development
    console.log("Device registered. Access token: " + token);

}, (errorMessage: String) => {
    this.updateMessage(JSON.stringify(errorMessage));
});

//code after

Please let me know if it is something I am doing wrong. Thank you!

lini commented 6 years ago

The error indicates that you did not pass the settings object for the push notifications register function. Looking at the code you pasted, perhaps you need to fix the parameter of the register function call from this.pushSettings to pushSettings.

lumayara commented 6 years ago

Thank you @lini ! It worked :)