Ejemplo n.º 1
1
 sendNotification = () => {
   const sendAt = new Date().getTime() + this.state.setRestTime * 1000;
   PushNotification.localNotificationSchedule({
     id: '0',
     message: `Select to return to ${this.props.exercise.name}`,
     title: 'Rest After Exercise Complete',
     ticker: 'Rest Complete',
     smallIcon: 'drawable/ic_sync',
     sendAt: sendAt.toString(),
   });
   this.setState({ sendAt });
   this.timer = setInterval(() => {
     if (this.timer &&
       (!this.state.sendAt || (this.state.sendAt && this.state.sendAt <= new Date().getTime()))) {
       clearInterval(this.timer);
       this.timer = null;
     }
     this.setState({ currentTime: new Date().getTime() });
   }, 100);
 };
Ejemplo n.º 2
0
 saveItem(state)
 {
   var self = this;
   if(state.type && state.date)
   {
     if(state.date.length === 10)
     {
         var now = new Date();
         var first = parseInt(state.date.substring(0,2));
         var second = parseInt(state.date.substring(3,5))-1;
         var third = parseInt(state.date.substring(6,10));
         var date = new Date();
         date.setDate(first);
         date.setMonth(second);
         date.setFullYear(third,second,first);
         date.setHours(now.getHours());
         date.setMinutes(now.getMinutes());
         date.setSeconds(now.getSeconds()+5);
       //  alert(date.toLocaleString());
         
         PushNotification.localNotificationSchedule({
             id:state.id,
             type:state.type,
             message: "Din "+state.type+" holder på å gå ut!", // (required)
             date: date
         });
     }
     self.writeToDb(state);
      self.replaceAt('dairy');
   }
   else{
     alert("fyll inn informasjon!");
   }
 }
  scheduleNotif() {
    this.lastId++;
    PushNotification.localNotificationSchedule({
      date: new Date(Date.now() + (30 * 1000)), // in 30 secs

      /* 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: "blue", // (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: "Scheduled Notification", // (optional)
      message: "My Notification Message", // (required)
      playSound: true, // (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)
    });
  }
  handleAppStateChange(appState) {
    if (appState === 'background') {
      let date = new Date(Date.now() + (this.state.seconds * 1000));

      if (Platform.OS === 'ios') {
        date = date.toISOString();
      }

      PushNotification.localNotificationSchedule({
        message: "My Notification Message",
        date,
      });
    }
  }