TypeError:undefined不是对象(评估'RNAlarmNotification.scheduleAlarm')

时间:2019-04-04 11:59:32

标签: reactjs react-native react-native-android

我可以使用react-native-alarm-notification

还有其他选择吗?

react-native-alarm-notification如何正确设置反应本机应用程序中的

反应本地警报中的此类错误

1)TypeError:undefined不是对象(正在评估    'RNAlarmNotification.scheduleAlarm')

代码:

从'react'导入React;

从“ react-native-alarm-notification”导入ReactNativeAN;

const fireDate = ReactNativeAN.parseDate(new Date(Date.now()+ 2000));

导入{StyleSheet,KeyboardAvoidingView,按钮,文本,视图,图像,

TextInput,ActivityIndi​​cator}来自“ react-native”;

const alarmNotifData = {     id:“ 12345”,
    标题:“我的通知标题”,
    消息:“我的通知消息”,
    频道:“ my_channel_id”,
    股票代码:“我的通知栏”,     auto_cancel:是,
    震动:是的,     振动:100,
    small_icon:“ ic_launcher”,
    large_icon:“ ic_launcher”,     play_sound:是的,     sound_name:null,
    红色”,     schedule_once:是的,
    标签:“ some_tag”,     fire_date:fireDate,
    数据:{foo:“ bar”}, };

export default class calendar extends React.Component {

constructor(props){

    super(props);

const alarmNotifData = {
    id: "12345",                                  // Required
    title: "My Notification Title",               // Required
    message: "My Notification Message",           // Required
    channel: "my_channel_id",                     // Required. Same id as specified in MainApplication's onCreate method
    ticker: "My Notification Ticker",
    auto_cancel: true,                            // default: true
    vibrate: true,
    vibration: 100,                               // default: 100, no vibration if vibrate: false
    small_icon: "ic_launcher",                    // Required
    large_icon: "ic_launcher",
    play_sound: true,
    sound_name: null,                             // Plays custom notification ringtone if sound_name: null
    color: "red",
    schedule_once: true,                          // Works with ReactNativeAN.scheduleAlarm so alarm fires once
    tag: 'some_tag',
    fire_date: fireDate,                          // Date for firing alarm, Required for ReactNativeAN.scheduleAlarm.

    // You can add any additional data that is important for the notification
    // It will be added to the PendingIntent along with the rest of the bundle.
    // e.g.
    data: { foo: "bar" },
};

        this.state = {
            data: alarmNotifData
        }
}
componentDidMount() {

    this.method();

  }

  method(){

         ReactNativeAN.scheduleAlarm(this.state.data);

         ReactNativeAN.deleteAlarm("12345");

         ReactNativeAN.stopAlarm();

         ReactNativeAN.sendNotification(this.state.data);   

         ReactNativeAN.getScheduledAlarms().then(this.state.data);

         ReactNativeAN.removeAllFiredNotifications()

         ReactNativeAN.removeFiredNotification("12345")

         ReactNativeAN.cancelAllNotifications()

         ReactNativeAN.cancelNotification("12345")
    }

0 个答案:

没有答案