【问题标题】:Push notifications IOS react native NSDictionary error推送通知 IOS 反应原生 NSDictionary 错误
【发布时间】:2020-05-07 09:46:27
【问题描述】:

我使用这个库在我的 react 本机应用程序中创建推送通知。

https://github.com/zo0r/react-native-push-notification.

我尝试发送本地通知,代码是:

localNotif() {
    this.lastId++;
    PushNotification.localNotification({
      /* Android Only Properties */
      id: ''+this.lastId, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
      ticker: "My Notification Ticker", // (optional)
      autoCancel: true, // (optional) default: true
      largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
      smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher"
      bigText: "My big text that will be shown when notification is expanded", // (optional) default: "message" prop
      subText: "This is a subText", // (optional) default: none
      color: "red", // (optional) default: system default
      vibrate: true, // (optional) default: true
      vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
      tag: 'some_tag', // (optional) add tag to message
      group: "group", // (optional) add group to message
      ongoing: false, // (optional) set whether this is an "ongoing" notification

      /* iOS only properties */
      alertAction: 'view', // (optional) default: view
      category: null, // (optional) default: null
      userInfo: null, // (optional) default: null (object containing additional notification data)

      /* iOS and Android properties */
      title: "Local Notification", // (optional)
      message: "My Notification Message", // (required)
      playSound: false, // (optional) default: true
      soundName: 'default', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
      number: '10', // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
      actions: '["Yes", "No"]',  // (Android only) See the doc for notification actions to know more
    });
  }

我收到了这个错误:

NSNull 类型的 JSON 值无法转换为 NSDisctionary

【问题讨论】:

  • 你能放一个错误屏幕吗?
  • 这是我在 Iphone 中收到的唯一错误消息
  • 这是崩溃(红屏)还是只有警告信息?
  • 红屏(我认为 userInfo 属性不能为空)但我不知道应该是什么类型

标签: ios react-native push-notification expo


【解决方案1】:

尝试在您的 JSON 中进行以下更改:

 category: null, // either pass a string here OR Remove this.
 userInfo: null, // either pass a JSON here OR Remove this.
 number: '10' // make this a number as 10 

这可能是一个可能的错误。希望这对你有用。

【讨论】:

  • @KhaledBoussoffara :删除类别和 userInfo 和密码:10。请阅读我的代码 sn-p 行前的注释
  • 我删除了 category 和 userInfo,并将数字设置为 10,我没有收到任何错误信息,我没有收到任何推送
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-17
  • 2017-12-18
  • 1970-01-01
  • 1970-01-01
  • 2016-05-29
  • 1970-01-01
相关资源
最近更新 更多