Skip to content

UNNotification:request 属性 ​

request 属性是这条通知来自的那个请求:标识、内容、触发方式都在它上面。

值 ​

UNNotificationRequest。

  • 只读。给它赋值抛 TypeError:request is read-only。
  • 远程推送的通知也有,它的 trigger 是 UNPushNotificationTrigger,content.userInfo 是推送的负载。
  • 不是当初交给系统的那个对象,内容相同。

示例 ​

js
const center = UNUserNotificationCenter.currentNotificationCenter();
center.addEventListener('notification', (event) => {
  const request = event.notification.request;
  console.log(request.identifier, request.content.title);
});

效果(未在模拟器验证):App 在前台时到了一条通知,输出它的标识和标题。

对应的 iOS API ​

UNNotification.request。

参见 ​