【问题标题】:react-native-push-notification doesn't work on ios DEVICEreact-native-push-notification 在 ios DEVICE 上不起作用
【发布时间】:2018-02-05 11:02:06
【问题描述】:

我正在使用react-native-push-notification,但我遇到了问题。
使用IOS simulatorandroid emulator,一切正常。
但是对于real iphone device,推送通知不起作用。 (在发布模式或调试模式下,两者都不起作用。

这是我的设置。

Link binary with Libraries

Set Search Header Path

我在 XCODE 上查看Capabilities/Background Modes/Remote notification

和 PushNotification.configure

import React from 'react';
import PushNotification from 'react-native-push-notification';

import {
    Auth
} from '../config/router';
import './ReactotronConfig';

export default class App extends React.Component {
    constructor(props) {
        super(props);

        this.PushConfigure();
    }
    PushConfigure() {
        PushNotification.configure({
            onNotification: (notification) => {
                console.log('NOTIFICATION:', JSON.stringify(notification));
            },
            permissions: {
                alert: true,
                badge: true,
                sound: true,
            },
            popInitialNotification: true,
            requestPermissions: true,
        });
    }
    render() {
        return <Auth />;
    }
}

当我必须推送通知时

    const date = new Date(Date.now());
    PushNotification.localNotificationSchedule({
        title: '메세지가 도착 했습니다.',
        message: `${data.user._id}: ${data.text}`,
        date,
        actions: 'Yes',
    });

正如我之前所说,通知适用于所有 simulator(Xcode IOS、android)。
但我不知道为什么通知在real IOS device 上不起作用。

如果您想对我的项目有更多的环境或设置,请发表评论。

更新 -

我没有在Apple Developer Program注册。
这就是我无法在真实 IOS 设备上使用通知的原因吗?

【问题讨论】:

  • 应用在真机上首次运行时是否要求通知权限?
  • 请检查应用询问通知权限并检查推送通知证书是否完善
  • @DinithMinura 是的。权限弹出发生。
  • @NisargThakkar 我在 XCODE 的 CAPABILITIES 中检查了远程通知,第一次运行应用程序时,出现了权限弹出窗口。还有什么要检查的吗?
  • 我没有注册 Apple Developer Program。这就是我不能在真正的 IOS 设备上使用通知的原因吗?

标签: ios react-native notifications device simulator


【解决方案1】:

是的,我认为推送通知在 iOS 模拟器中不起作用,因此您需要在真实设备中检查这一点,并在发布版本时检查推送通知的证书是否正确。

还请检查您是否在onRegister 函数上获得了正确的设备令牌

PushNotification.configure({
           onRegister: function (token) {
                console.log((token);
            },
            onNotification: (notification) => {
                console.log('NOTIFICATION:', JSON.stringify(notification));
            },
            permissions: {
                alert: true,
                badge: true,
                sound: true,
            },
            popInitialNotification: true,
            requestPermissions: true,
        });

请确保在设置中为您的应用启用推送通知

【讨论】:

  • 有没有办法在本地弹出通知而不连接到任何服务器,如firebase、APN ..?
  • 是的,有办法请点击链接。这将帮助您获得本地通知 github.com/zo0r/react-native-push-notificationmedium.com/differential/…
  • 我一开始关注了他们,但是通知在真正的IOS设备上不起作用。
  • 有什么解决办法吗?我收到提示以允许在我的真实设备上进行用户通知,并且我已注册 Apple 开发程序,但我没有在终端中看到注册令牌控制台日志...
【解决方案2】:

由于Xcode 11.4 - IOS 模拟器也应该支持推送通知

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-04
    • 1970-01-01
    • 2018-12-29
    • 2019-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多