-
-
Notifications
You must be signed in to change notification settings - Fork 44
IOS: Device registered but no push notifications are received (from Firebase) #201
Description
Notifications are never received (nor with the app running in foreground or background) in IOS devices although the device is correctly registered.
The apple developer account certificates were created/configured including the app id with push notifications enabled:
An authentication APN key was created on apple developer account and added to the corresponding IOS app configuration in the cloud messaging tab in the project configuration in firebase. The file GoogleService-Info.plist was downloaded from firebase and copied to <Project folder>/app/App_Resources/iOS/.
In addition, push notifications were enabled on xcode (project capabilities):
and the resulting entitlements file was copied from
<Project folder>/platforms/ios/<Project name>/Resources to <Project folder>/app/App_Resources/iOS/
app.component.ts :
import { Component } from "@angular/core";
import { Observable } from "tns-core-modules/data/observable";
import * as pushPlugin from "nativescript-push-notifications";
@Component({
selector: "ns-app",
templateUrl: "app.component.html",
})
export class AppComponent extends Observable{
private pushSettings = {
// Android settings
senderID: "XXXXXXX", // Android: Required setting with the sender/project number
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
interactiveSettings: {
actions: [{
identifier: 'READ_IDENTIFIER',
title: 'Read',
activationMode: "foreground",
destructive: false,
authenticationRequired: true
}, {
identifier: 'CANCEL_IDENTIFIER',
title: 'Cancel',
activationMode: "foreground",
destructive: true,
authenticationRequired: true
}],
categories: [{
identifier: 'READ_CATEGORY',
actionsForDefaultContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER'],
actionsForMinimalContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER']
}]
},
notificationCallbackIOS: (message: any) => {
this.updateMessage("Message received!\n" + JSON.stringify(message));
}
};
private _counter: number;
private _message: string;
constructor() {
super();
this.message = "";
this.updateMessage("App started.");
let self = this;
this.onRegisterButtonTap();
}
get message(): string {
return this._message;
}
set message(value: string) {
if (this._message !== value) {
this._message = value;
this.notifyPropertyChange("message", value);
}
}
onRegisterButtonTap() {
let self = this;
pushPlugin.register(this.pushSettings, (token: String) => {
self.updateMessage("Device registered. Access token: " + token);
// token displayed in console for easier copying and debugging durng development
console.log("Device registered. Access token: " + token);
if(this.pushSettings.interactiveSettings) {
if (pushPlugin.registerUserNotificationSettings) {
pushPlugin.registerUserNotificationSettings(() => {
self.updateMessage("Successfully registered for interactive push.");
console.log("Successfully registered for interactive push");
}, (err) => {
self.updateMessage("Error registering for interactive push: " + JSON.stringify(err));
console.log("Error registering for interactive push: " + JSON.stringify(err));
});
}
}
}, (errorMessage: String) => {
self.updateMessage(JSON.stringify(errorMessage));
console.log(JSON.stringify(errorMessage));
});
}
private updateMessage(text: String) {
this.message += text + "\n";
}
}
Output:
...
CONSOLE LOG file:///app/app.component.js:71:24: Device registered. Access token: eeed45c4f9f77cecd72148c2f497bb1f57d8c5829d418e25d65e463a45c96daf
CONSOLE LOG file:///app/app.component.js:76:36: Successfully registered for interactive push
but then when trying to send a notification from firebase to all devices (with the app installed/registered) no message is received. When sending a notification to a specific device (using the access token) it fails directly on firebase notifications server with the error: "Invalid token. Please check token format".
Note: In Android both options are working fine (the token is also correct).
Which platform(s) does your issue occur on?
- iOS
- iOS version: IOS 10.3.3
- emulator or device: device. What type of device? iPhone 5.
Please, provide the following version numbers that your issue occurs with:
- CLI: 3.4.1
- Cross-platform modules: ^3.4.0
- Runtime(s): tns-ios: 3.4.0
- Plugin(s):
"dependencies": {
"@angular/animations": "~4.4.1",
"@angular/common": "~4.4.1",
"@angular/compiler": "~4.4.1",
"@angular/core": "~4.4.1",
"@angular/forms": "~4.4.1",
"@angular/http": "~4.4.1",
"@angular/platform-browser": "~4.4.1",
"@angular/router": "~4.4.1",
"nativescript-advanced-webview": "^1.2.0",
"nativescript-angular": "~4.4.0",
"nativescript-geolocation": "^4.2.2",
"nativescript-google-maps-sdk": "^2.4.3",
"nativescript-ngx-fonticon": "^4.0.0",
"nativescript-pro-ui": "^3.2.0",
"nativescript-pulltorefresh": "^2.0.3",
"nativescript-push-notifications": "^1.1.0",
"nativescript-theme-core": "~1.0.2",
"nativescript-web-image-cache": "^4.2.2",
"reflect-metadata": "~0.1.8",
"rxjs": "~5.4.2",
"tns-core-modules": "^3.4.0",
"zone.js": "~0.8.2"
},
"devDependencies": {
"babel-traverse": "6.26.0",
"babel-types": "6.26.0",
"babylon": "6.18.0",
"lazy": "1.0.11",
"nativescript-dev-typescript": "~0.5.0",
"typescript": "~2.4.2"
}

