我正在尝试将通知从firebase控制台发送到我的react本机应用程序
据我所知,我遵循了这里糟糕的文档:https://invertase.io/oss/react-native-firebase/v6/messaging/quick-start
我安装了@react native firebase/app和/messaging,下面是我在组件中的代码:
componentDidMount() {
this.reqNotifications()
this.checkNotificationPermission()
}
reqNotifications() {
requestNotifications(['alert', 'badge', 'sound']).then(({status, settings}) => {
console.log('NOTIFICATION STATUS' + status)
});
}
async checkNotificationPermission() {
const enabled = await messaging().hasPermission();
if (enabled) {
console.log('APPROVED');
await messaging().registerForRemoteNotifications()
messaging().getToken().then(token => console.log('token: >> ' + token))
} else {
console.log('NOT APPROVED');
}
}
但我无法从firebase向设备发送任何信息;前景和背景都没有发生任何事情。我尝试了令牌测试,也尝试了正常测试,但没有,什么都没有发生。
我在componentDidMount中添加了以下代码:
messaging().onMessage(async remoteMessage => {
console.log('FCM Message Data:', remoteMessage.data);
});
据我所知,这是订阅云消息,当我从firebase控制台发送一些云消息通知时,我应该得到控制台输出;但什么都没发生。
我不知道我错过了什么,但我认为这个软件包有一个大的更新,大多数文档都是以前的版本,我真的停留在这里感谢您的帮助
for rnfirebase.io V6
componentDidMount = async () => {
this.checkNotificationPermission();
await messaging().requestPermission({provisional: true});
await messaging().registerDeviceForRemoteMessages();
await this.getFCMToken();
if (Platform.OS === 'android') {
this.createAndroidNotificationChannel();
}
this.backgroundState();
this.foregroundState();
};
checkNotificationPermission = () => {
firebase
.messaging()
.hasPermission()
.then(enabled => {
if (!enabled) {
this.promptForNotificationPermission();
}
});
};
promptForNotificationPermission = () => {
firebase
.messaging()
.requestPermission({provisional: true})
.then(() => {
console.log('Permission granted.');
})
.catch(() => {
console.log('Permission rejected.');
});
};
createAndroidNotificationChannel() {
const channel = new firebase.notifications.Android.Channel(
'channelId',
'Push Notification',
firebase.notifications.Android.Importance.Max,
).setDescription('Turn on to receive push notification');
firebase.notifications().android.createChannel(channel);
}
foregroundState = () => {
const unsubscribe = messaging().onMessage(async notification => {
console.log('Message handled in the foregroundState!', notification);
});
return unsubscribe;
};
// Register background handler
backgroundState = () => {
messaging().setBackgroundMessageHandler(async notification => {
console.log('Message handled in the background!', notification);
});
};
我无法通过parse.com正确设置推送通知。我相信我的推送是因为它们通过解析显示在我的推送日志中。但是,无论我的推送发送到哪里(app或仪表盘),“发送的推送”总是显示0。我知道这可能是一个复杂的任务,所以任何帮助将是非常感谢!下面是我的代码: AppDelegate.m InboxTableViewController.m ViewDidLoad
让我的应用程序收到5个远程通知。每当我点击单个通知时,所有5个通知都消失了,我们需要完整地显示其他4个通知,直到它们点击。但主要问题是所有其他通知都是为了其他目的,而不是为了相同的目的。因此,我们需要显示所有通知,直到从通知托盘中单击它们。 我们还需要根据此更新徽章计数。有什么方法来处理远程消息推送时,应用程序不运行(被杀)?您能否建议使用目标c处理远程推送通知的更好方法? 谢啦
我已经设置了一个启用推送通知的iOS应用程序。 我可以将消息推送到应用程序,例如,徽章计数工作并相应更新。 但是我从来没有在锁屏或其他地方看到标准的推送通知弹出窗口,尽管手机会震动,所以信息可以通过。 即使应用程序关闭或不在后台。 这是有效载荷:
这是舱单 这是我的注册令牌类 这是我的Firebase服务类
我用push notification与解析服务器连接了应用程序,但问题是我遇到了错误,它说:registerforRemotenotification类型在IOS 8.0版本中不推荐使用:请使用register for remote notification和register user notification设置。但这段代码是针对iOS8的。 有谁能帮我找到正确的代码吗?
iOS消息推送在工作灯,接收通知时,应用程序在后台作为徽章,但当我点击徽章也我得到有效载荷作为警报。我只需要徽章时,应用程序在后台运行。 实际上,我需要在应用程序位于前台时显示警报,如果应用程序位于后台,则显示徽章。在我的push received handler函数中,我正在检查这一点。但在ios中,只有当用户点击badge时,处理器函数get才会触发,而在Android中,当push收到时,处