用于同步离子应用程序的外部 Android 服务
External Android Service to Sync ionic App
我正在尝试获取离子应用程序以在启动应用程序图标时获取通知徽章。
据我所知,如果离子应用程序关闭(不在后台)是不可能的,所以,任何人都知道是否可以创建一个 android 服务,我总是 运行 在后台和同步我的离子应用程序,更新图标徽章?
提前致谢
既然@Shiben问了,我就是这样解决的
安装 cordova-plugin-firebase
转到 https://firebase.google.com 并创建您的 firebase 项目(请参阅配置指南)
-在您的 app.component.ts 中执行如下操作:
export class MyApp {
rootPage:any = HomePage;
firebase : any;
constructor(public platform: Platform,
public statusBar: StatusBar,
public splashScreen: SplashScreen,
private _firebase: Firebase,
public alertCtrl: AlertController) {
platform.ready().then(() => {
(your things)
this.firebase = _firebase;
this.initFirebase();
this.firebase.setBadgeNumber(0);
});
}
这是我的 initFirebase():
initFirebase(){
this.firebase.grantPermission();
this.firebase.onTokenRefresh()
.subscribe((token: string) => localStorage.setItem("pushToken", token))
this.firebase.onNotificationOpen()
.subscribe((notification) => {
let alert = this.alertCtrl.create({
title: 'New Notification',
subTitle: "Your notification",
buttons:['OK']
});
alert.present();
});
}
-在你的 index.html 中插入这样的东西(你从 firebase 得到的)
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "your key",
authDomain: "your domain",
databaseURL: "your url",
projectId: "your projid",
storageBucket: "your storagebucket",
messagingSenderId: "your messageid"
};
firebase.initializeApp(config);
</script>
我很久以前就这样做了,有些事情可能会有所改变。这可能会被弃用,也可能不是最佳做法,但是,我希望它能让您朝着正确的方向前进。
我正在尝试获取离子应用程序以在启动应用程序图标时获取通知徽章。 据我所知,如果离子应用程序关闭(不在后台)是不可能的,所以,任何人都知道是否可以创建一个 android 服务,我总是 运行 在后台和同步我的离子应用程序,更新图标徽章?
提前致谢
既然@Shiben问了,我就是这样解决的
安装 cordova-plugin-firebase
转到 https://firebase.google.com 并创建您的 firebase 项目(请参阅配置指南)
-在您的 app.component.ts 中执行如下操作:
export class MyApp {
rootPage:any = HomePage;
firebase : any;
constructor(public platform: Platform,
public statusBar: StatusBar,
public splashScreen: SplashScreen,
private _firebase: Firebase,
public alertCtrl: AlertController) {
platform.ready().then(() => {
(your things)
this.firebase = _firebase;
this.initFirebase();
this.firebase.setBadgeNumber(0);
});
}
这是我的 initFirebase():
initFirebase(){
this.firebase.grantPermission();
this.firebase.onTokenRefresh()
.subscribe((token: string) => localStorage.setItem("pushToken", token))
this.firebase.onNotificationOpen()
.subscribe((notification) => {
let alert = this.alertCtrl.create({
title: 'New Notification',
subTitle: "Your notification",
buttons:['OK']
});
alert.present();
});
}
-在你的 index.html 中插入这样的东西(你从 firebase 得到的)
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "your key",
authDomain: "your domain",
databaseURL: "your url",
projectId: "your projid",
storageBucket: "your storagebucket",
messagingSenderId: "your messageid"
};
firebase.initializeApp(config);
</script>
我很久以前就这样做了,有些事情可能会有所改变。这可能会被弃用,也可能不是最佳做法,但是,我希望它能让您朝着正确的方向前进。