首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >收到了防火墙云消息通知,但没有弹出电容/推送通知。

收到了防火墙云消息通知,但没有弹出电容/推送通知。
EN

Stack Overflow用户
提问于 2022-07-03 20:40:26
回答 1查看 488关注 0票数 0

在我的角13 Ionic 6应用程序中,我使用了电容/推送通知和FireBase,在我的服务中:

代码语言:javascript
运行
复制
import { EventEmitter, Injectable, Output } from '@angular/core';
import {ActionPerformed, PushNotifications, PushNotificationSchema, Token} from '@capacitor/push-notifications';
import {  Capacitor } from '@capacitor/core';
import { Dialogs, DialogType } from '../Utilities/dialogs';

import { get, set, remove } from './storage.service';
import { BehaviorSubject } from 'rxjs';
import { App } from '@capacitor/app';

//https://devdactic.com/push-notifications-ionic-capacitor/

@Injectable({
  providedIn: 'root'
})
export class FbNotificationsService {

  onFCMTokenChanged: BehaviorSubject<string> = new BehaviorSubject('');

  tokenProcessed: boolean = false;

  
  constructor(private dialogs: Dialogs) {
    
   }
 
  initPush() {
    if (Capacitor.getPlatform() !== 'web') {
      this.registerPush()
    } else {
      console.log('Web platform detected');
      this.onFCMTokenChanged.next('web-platform');
    }
  }
 
  private registerPush() {
    PushNotifications.requestPermissions().then((permission) => {
      if (permission.receive === 'granted') {
        // Register with Apple / Google to receive push via APNS/FCM
        console.log('FB Permission granted');
        PushNotifications.register(); //Registers app to receive notifications
      } else {
        // No permission for push granted by user on iOS
        console.log('FB NO permissions granted');
      }
    });
 
    PushNotifications.addListener(
      'registration',
      (token: Token) => {        
        if ((token)&&(!this.tokenProcessed)) {
          this.tokenProcessed = true;
          console.log('My token: ' + JSON.stringify(token));
          this.onFCMTokenChanged.next(token.value);

          set('device-token', token.value); 
        }
         
      });
 
      PushNotifications.addListener('registrationError', (error: any) => {
        console.log('Registration Error: ' + JSON.stringify(error));
        this.dialogs.dialogClose('Network Error','The network signal is not sufficient at this time. Please improve connection and try again');
        App.exitApp();
        
      });
 
    PushNotifications.addListener(
      'pushNotificationReceived',
      async (notification: PushNotificationSchema) => {
        console.log('Push received: ' + JSON.stringify(notification));
        alert('Push received: ' + JSON.stringify(notification));
        //What to do next. Notification received on the device.
      }
    );
 
    PushNotifications.addListener(
      'pushNotificationActionPerformed',
      async (notification: ActionPerformed) => {
        const data = notification.notification.data;
        console.log('Action performed: ' + JSON.stringify(notification.notification));
        alert('Push action performed: ' + JSON.stringify(notification));
        //What to do next. data holds all payload fields of the notification object
      }
    );
  }
}

我遵循的基本指南是这里

当我从Firebase控制台发送测试消息时,我放置的警报语句将弹出,这意味着应用程序接收到消息:

代码语言:javascript
运行
复制
alert('Push received: ' + JSON.stringify(notification)); //WORKING

但是,操作系统没有弹出通知消息供用户查看。我总是收到来自Whatapp、电子邮件等的通知,“不打扰”设置被关闭。

这是有经验的两款安卓设备:小米Rednote 8和三星Galaxy A32。

我是不是遗漏了什么?

EN

回答 1

Stack Overflow用户

发布于 2022-07-26 08:39:38

我以前也遇到过类似的问题,也许下面的信息可以帮助你:

当你的安卓应用程序在前台时,PushNotifications不会出现在屏幕上。

如果您绝对希望看到通知的显示,则可以在收到推送通知时创建本地通知。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72849760

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档