angular - Ionic 在一个信号推送通知上没有警报
问题描述
我正在使用 ionic 和 OneSignal 进行推送通知。到目前为止,我可以收到通知,但如果我点击它,什么也不会发生。如果应用程序显示“通知已打开”之类的警报,那将是很好的测试。我的目标是,应用程序路由到特定页面或模式,但这现在并不重要。
import { Component } from '@angular/core';
import { Platform,AlertController } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss']
})
export class AppComponent {
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,private alertCtrl: AlertController) {
platform.ready().then(() => {
statusBar.styleDefault();
splashScreen.hide();
//Remove this method to stop OneSignal Debugging
window["plugins"].OneSignal.setLogLevel({logLevel: 6, visualLevel: 0});
// Set your iOS Settings
var iosSettings = {};
iosSettings["kOSSettingsKeyAutoPrompt"] = false;
iosSettings["kOSSettingsKeyInAppLaunchURL"] = false;
window["plugins"].OneSignal
.startInit("my key is in here")
.handleNotificationOpened(function(openResult)
{
this.showAlert('Notification opened', 'You already read this before',JSON.stringify(openResult));
console.log('Notification opened: ' + JSON.stringify(openResult));
})
.iOSSettings(iosSettings)
.inFocusDisplaying(window["plugins"].OneSignal.OSInFocusDisplayOption.Notification)
.endInit();
// The promptForPushNotificationsWithUserResponse function will show the iOS push notification prompt. We recommend removing the following code and instead using an In-App Message to prompt for notification permission (See step 6)
window["plugins"].OneSignal.promptForPushNotificationsWithUserResponse(function(accepted) {
console.log("User accepted notifications: " + accepted);
});
});
}
async showAlert(title, msg, task) {
const alert = await this.alertCtrl.create({
header: title,
subHeader: msg,
buttons: [
{
text: `Action: ${task}`,
handler: () => {
// E.g: Navigate to a specific screen
}
}
]
})
alert.present();
}
}
有人可以帮助我吗?为什么我看不到任何警报?谢谢
解决方案
推荐阅读
- javascript - JQuery UI Resizable 防止:专注于句柄内的 div
- node.js - Docker 不公开节点和 webpack 开发服务器的端口
- android - 视频通话时需要检测人脸。使用 OpenTok 或 TockBox 视频通话
- azure - 如何记录 Azure 服务总线访问?
- html - R Stargazer 错误 - 使用 add.lines 参数时如何导出为 .html?
- c# - 设置 this.BindingContext = this; 似乎不适用于我的页面和 Xamarin.Forms 中的绑定
- debugging - C程序运行时崩溃,在GDB中工作
- c# - 如何将数据库数据格式化为同一行中的excel c#
- android - 如何更改在 layout.addview 上以编程方式添加的 textview 的大小
- postgresql - PostgreSQL数据库表中的重复唯一约束