【问题标题】:Hide push notifications on Ionic app when app is running应用程序运行时隐藏 Ionic 应用程序上的推送通知
【发布时间】:2017-07-17 06:57:55
【问题描述】:

我正在从 Parse 服务器向 Ionic 应用发送推送通知,该应用正在使用 ParsePushPlugin:https://github.com/taivo/parse-push-plugin

按照说明,我设法正确接收推送通知。

但即使我的应用程序在前台运行,插件仍然在我的应用程序顶部显示通知,这非常令人困惑。

我尝试监听应用程序运行时收到推送通知的事件。但通知仍在显示:

ParsePushPlugin.on('receivePN', function(pn:any){
  console.log('yo i got this push notification:' + JSON.stringify(pn));
}, function(error:any){
  console.error( error);
}); 

应用已经在前台运行时如何隐藏通知?

【问题讨论】:

    标签: ionic-framework parse-platform push-notification ionic3


    【解决方案1】:

    在推送插件的 OPTIONS 中进行以下更改,forceShow 将在应用前台隐藏通知:

    {
            "android": {
                "senderID": "XXXXXXXXXX",
                "forceShow": "false",
                "badge": "true"
                },
            "ios": {
                "alert": "true",
                "badge": "true",
                "sound": "true",
                "forceShow": "false"
            },
            "windows": {}
        }
    

    For more info you can click here

    【讨论】:

    • 啊,谢谢。我没有使用那个插件。但我会试试那个插件......
    • 使用这个更容易:如果有任何问题,请告诉我:):stackoverflow.com/questions/29771478/…
    • 如果我使用解析来发送推送通知并且插件似乎不是为解析而设计的,这有关系吗?
    • 不幸的是,我在尝试使用该插件时遇到了另一个奇怪的问题,您能帮我看看吗? stackoverflow.com/questions/45156690/…
    【解决方案2】:

    最后我意识到我可以停止通知的唯一方法是修改 ParsePushPlugin.m

    -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
        NSLog(@"User info %@", notification.request.content.userInfo);
    
        UIApplication *application = [UIApplication sharedApplication];
        [self jsCallback:notification.request.content.userInfo withAction:(application.applicationState == UIApplicationStateActive) ? @"RECEIVE" : @"OPEN"];
    
        //added this line to hide the notification
        completionHandler(UNNotificationPresentationOptionNone);
    
        //commented out this line to hide the notification
        //completionHandler(UNNotificationPresentationOptionAlert);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多