【问题标题】:React Native PushNotification IOS can receive push message but without soundReact Native Push Notification IOS可以收到推送消息但没有声音
【发布时间】:2018-09-12 04:19:45
【问题描述】:

我在使用 React Native 时遇到了 PushNotificationIOS 的问题。在我将 RN 从 0.48 更新到 0.54 并将我的 iPhone 升级到 iOS 11.3 后,我的 iOS 应用可以接收推送消息,但没有声音。代码的通知部分保持不变,消息声音没有问题。只是想知道可能需要进行什么配置才能使消息听起来正常。感谢您的建议。

我在调试模式下检查通知对象,它有警报标题、正文和应该值并且看起来不错。

    componentWillMount() {
        PushNotificationIOS.addEventListener("register", this._onRegistered);
        PushNotificationIOS.addEventListener(
          "registrationError",
          this._onRegistrationError
        );
        PushNotificationIOS.addEventListener(
          "notification",
          this._onRemoteNotification
        );
        PushNotificationIOS.addEventListener(
          "localNotification",
          this._onLocalNotification
        );
      }
    ....

    _onRegistered(deviceToken) {
       if (deviceToken)
...
        console.log("Registered deviceToken=" + deviceToken);
      }

    _onRemoteNotification(notification) {
        notification.finish(PushNotificationIOS.FetchResult.NoData);
        var body = notification.getMessage().body.split("|");
        if (body.length === 1)
          Warn(
            notification.getMessage().title, //message only.
            body[0],
            [{ text: "OK", onPress: null }]
          );
        else if (body.length === 2) {
          //code + message
          Warn(notification.getMessage().title, body[0] + "\n" + body[1], [
            { text: "OK", onPress: null }
          ]);
          store.dispatch(sessionActionCreators.updateConfirmCode(body[0]));
        }
      }

【问题讨论】:

    标签: ios react-native push-notification


    【解决方案1】:

    How to make sound when notification came if application is active in ios?

    刚刚发现如果应用程序处于前台,则强制播放声音事件是可能的。只需调用 API 播放声音/做振动。

    【讨论】:

      猜你喜欢
      • 2018-12-29
      • 1970-01-01
      • 2021-11-19
      • 1970-01-01
      • 1970-01-01
      • 2020-07-16
      • 2021-07-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多