cordova iOS通知在前台不起作用

时间:2016-08-01 08:24:11

标签: ios cordova push-notification alert foreground

我正在使用Cordova和插件phonegap-plugin-push, 当我的应用程序在前台时,我没有看到通知警报。 我该怎么办? (我知道在Android平台上这样做的方法(在pushNotification的方法init中设置“forceShow”:true)但这仅适用于Android) 提前感谢您的回复。

3 个答案:

答案 0 :(得分:1)

如果您不想触摸ios原生物,那么您可以通过以下方法显示您自己的custmize html / css Banner(如iOS push Baner):

push.on('notification', function(data) {
    If(platform == "iOS" && data.additionalData.foreground){
    // Show your Baner here
// U can also define call back on clicking of that banner
//Like navigation to respective page or close that banner
});

答案 1 :(得分:0)

迪妮丝

通知不在前台工作。它只适用于后台。在前台处理它需要在委托方法中实现逻辑。 下面是Objective C代码片段,用于在前台显示通知。

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    application.applicationIconBadgeNumber = 0;
    //self.textView.text = [userInfo description];
    // We can determine whether an application is launched as a result of the user tapping the action
    // button or whether the notification was delivered to the already-running application by examining
    // the application state.

    if (application.applicationState == UIApplicationStateActive)
    {
        // Nothing to do if applicationState is Inactive, the iOS already displayed an alert view.
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Did receive a Remote Notification" message:[NSString stringWithFormat:@"Your App name received this notification while it was running:\n%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]]delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

        [alertView show];
    }    
}

它可以帮助您解决问题。

答案 2 :(得分:0)

在iOS中,如果您的应用位于前台,则不会显示推送通知提醒。要实现它,如果应用程序位于前台,您应该在推送通知接收委托中编写警报代码。要了解iOS中的应用程序状态,这就是代码。

+(BOOL) runningInForeground
{
UIApplicationState state = [UIApplication sharedApplication].applicationState;

return state == UIApplicationStateActive;

}