代码之家  ›  专栏  ›  技术社区  ›  Sumit Jangra

读取getDeliveredNotifications(completionHandler:)方法中的推送通知负载详细信息

  •  4
  • Sumit Jangra  · 技术社区  · 7 年前

    这是我的推送通知负载。

    {
        "userId":"QA-207-222820",
        "title":"Push new Notification",
        "message":"New Notification",
        "deviceId":"70",
        "deviceName":"R70",
        "notificationType":"1"
    }
    

    无法读取内部通知对象中的上述有效负载键和值 getDeliveredNotifications ios10中的方法。

    下面是通知对象的详细信息 获取交付通知 方法

    <UNNotification: 0x1742389a0; date: 2017-12-13 09:34:59 +0000,
    
     request: <UNNotificationRequest: 0x1742389c0; identifier: 067437A1-E8F3-4805-B6D9-
    A57BE48E9554, 
    
    content: <UNNotificationContent: 0x17410ba30; title: (null), 
    subtitle: (null), body: New Notification 
    , categoryIdentifier: , launchImageName: , peopleIdentifiers: (
    ), threadIdentifier: , attachments: (
    ), badge: (null), 
    
    sound: <UNNotificationSound: 0x1740b75e0>, 
    hasDefaultAction: YES, defaultActionTitle: (null), shouldAddToNotificationsList: YES,
    shouldAlwaysAlertWhileAppIsForeground: NO, shouldLockDevice: NO, shouldPauseMedia: NO, 
    isSnoozeable: NO, fromSnooze: NO, darwinNotificationName: (null), darwinSnoozedNotificationName: (null), 
    
    trigger: <UNPushNotificationTrigger: 0x17400e2a0; contentAvailable: YES, mutableContent: NO>>>
    

    推送通知中没有关于我发送的有效负载的信息,除了我的通知消息“New notification”,该消息存在于通知对象的body key中,是否有任何方法可以读取通知对象中的所有有效负载键。任何帮助都将不胜感激。

    1 回复  |  直到 7 年前
        1
  •  11
  •   davidethell    7 年前

    您的负载应位于通知内容的userInfo字典中:

    let userInfo = notification.request.content.userInfo
    print userInfo["userId"]