-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
可以收到通知 , 但是通知栏不出来 #126
Comments
JS事件监听能收到push通知,但是不弹出通知栏。 |
我翻看了下阿里云推送官方文档,官方建议 自建通知。
给一段我的代码参考: handleAliyunPushMessage = (msg) => {
console.debug('AliyunPush message received:', JSON.stringify(msg))
/*
* `msg`结构说明:
* msg.type: "notification":通知 或者 "message":消息
* msg.title: 推送通知/消息标题
* msg.body: 推送通知/消息具体内容
* msg.actionIdentifier: "opened":用户点击了通知, "removed"用户删除了通知, 其他非空值:用户点击了自定义action(仅限ios)
* msg.extras: 用户附加的{key:value}的对象
*/
try {
const { appState } = this.state
if (msg.type === 'notification') { // 处理通知
if (appState !== 'active' && msg) { // APP不处于前台时,才处理通知。前台则忽略通知
if (Platform.OS === 'android') {
// 阿里云推送官方文档,建议`自建通知`
// 参考: https://help.aliyun.com/document_detail/53546.html
Notifications.presentLocalNotificationAsync({
title: msg.title,
body: msg.body,
android: {
channelId: 'your app notification channel_id', // 与Android `MainApplication.createNotificationChannel()` 中配置相同
icon: 'your app icon url',
color: 'your app icon color',
},
}).catch((err) => {
console.debug('Android presentLocalNotificationAsync() failed:', err)
})
} else if (Platform.OS === 'ios') {
// todo: 处理 iOS 通知
}
}
} else if (msg.type === 'message') { // 处理消息
}
} catch (err) {
console.error('An error occurred while processing the AliyunPush message.', err)
}
}
react-native原生文档我没找到 可以使用 https://github.com/wix/react-native-notifications 或者 直接Java原生扩展,参考阿里官方的文档。 |
请问您说的这种情况是不是app是前台打开的,或者在后台运行时发生的,并不是app被关闭的时候。我想确认一下app在后台运行,以及app被杀死后是否能弹出通知。这也是最基础的能力 |
@charmtiger 以上描述的是,android环境,app处于 iOS 无论是进程被杀死,还是后台运行,都能正确接收推送,并弹出通知。 |
The same as me. |
有更好的解决方案吗? |
The text was updated successfully, but these errors were encountered: