我正在使用 nativescript-angular 框架开发 android 和 iOS 应用程序。我正在为 fcm 推送通知使用nativescript-plugin-firebase 插件。在 iOS 平台中,通知在前台和后台都出现。但是在android中,只有当应用程序在后台时才会收到通知。
我们如何解决这个问题?
我的 Firebase 初始化代码:
firebase.init({
showNotifications:true,
showNotificationsWhenInForeground:true,
onPushTokenReceivedCallback:(token)=>{
console.log("onPushTokenReceivedCallback:",{token});
},
onMessageReceivedCallback:(message:firebase.Message)=>{
console.log("onMessageReceivedCallback:",{message});
})
.then(()=>{
console.log("Initialized");
})
.catch(error=>{
console.log("Initialize",{ error });
});
Run Code Online (Sandbox Code Playgroud) 我学习用于开发android和ios应用程序的nativescript + angular.Iam工作和学习nativescript + angular的基本服务。在我的项目的post方法中,我在类型'typeof Observable'上没有错误'属性'throw'。我的代码是:
import { User } from "./user";
import { Config } from "../config";
import { Injectable } from "@angular/core";
import { Observable } from "tns-core-modules/ui/page/page";
@Injectable()
export class UserService {
constructor(private http: Http) { }
register(user: User) {
let headers = new Headers();
headers.append("Content-Type", "application/json");
return this.http.post(
Config.apiUrl + "Users",
JSON.stringify({
Username: user.email,
Email: user.email,
Password: user.password
}),
{ headers: headers }
)
.catch(this.handleErrors);
}
handleErrors(error:Response)
{
console.log(JSON.stringify(error.json()));
return Observable.throw(error);
}
}
Run Code Online (Sandbox Code Playgroud)