我收到PushNotification
中iOS
对react-native
的以下回复
{
"aps": {
"alert": "Next live session will start on 15-10-2018 13:00:00 for course NEET\/AIIMS",
"sound": "default",
"badge": 1,
"relData": {
"video_url": "",
"start_time": "15-10-2018 13:00:00"
}
}
}
如何使用start_time
从relData
获得PushNotificatonIOS
?
目前,我只能使用以下代码获取警报消息:
PushNotificationIOS.addEventListener('notification', function(notification) {
console.log('You have received a new notification! ', notification);
Alert.alert(notification.getMessage())
});
答案 0 :(得分:0)
将您的APNS notification
内容修改为以下格式。
{
"aps": {
"alert": {
"title": "Some Title",
"body": "Next live session will start on 15-10-2018 13:00:00 for course NEET\/AIIMS"
},
"sound": "default",
"badge": 1,
"mutable-content": 1,
"content-available": 1
},
"relData": {
"video_url": "",
"start_time": "15-10-2018 13:00:00"
}
}
要支持后台更新通知,请确保 有效负载的aps词典包含 content-available 键,其中包含一个 值 1 。如果有用户可见的更新与 后台更新,您可以在 APS字典(视情况而定)。
在AppDelegate.m的顶部:
#import <React/RCTPushNotificationManager.h>
然后在您的AppDelegate实现中添加以下内容:
// Required for the notification event. You must call the completion handler after handling the remote notification.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
[RCTPushNotificationManager didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
在上述方法中,您将在relData
中获得userInfo
以及其余的有效载荷。
有关更多信息,请访问https://facebook.github.io/react-native/docs/pushnotificationios