问题描述
我正在使用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();
}
}
有人可以帮我吗?为什么看不到任何警报? 谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)