2017-02-15 5 views
0

Ionic 2のローカル通知に関するヘルプが必要です。Ionic 2 LocalNotificationsの使用

私は、ユーザーがDateTimeピッカーから1時間を選択してから、その時間がユーザーによって示されたときに起動するアラームを保存することを許可します。私が持っている)(saveReminderで、実際に <ion-datetime pickerFormat="HH:mm" [(ngModel)]="time" cancelText="Cancelar" doneText="Aceptar"></ion-datetime>

<button ion-button block round (click)="saveReminder()">Guardar</button> 

public saveReminder(): void { 

     if (this.timePicked()) { 

      LocalNotifications.schedule({ 
       id: 1, 
       text: '¡Hora de meditar!', 
       at: new Date(new Date().getTime() + 5), 
       sound: 'file://audio/sound.mp3', 
       every: "day", 
       //data: { message : 'Informacion' }, 
       //icon: 'res://icon', 
       //smallIcon: 'res://ic_popup_sync' 
      }); 

      this.showSavedReminderMsg(); 
     } else { 
      this.showNoTimePickedError(); 
     } 

    } 

saveReminder()はローカルのスケジュールを設定

は、私は、これは時間を選んで、ユーザーを許可する必要がありますユーザーがボタンを押してから5秒後に表示される通知(テスト用のみ) 今、私はthiをスケジュールする方法を知る必要がありますユーザーが選択した日付の通知を送信します。

私の日付ピッカーは、 "08:45"のような文字列を返します。スケジューラに渡す時間と分を分けるための方法があるかどうか、または他の方法でこれを達成する方法が必要です。ここで

はDate.now(と説明公式イオンDOC)である: https://ionicframework.com/docs/v2/native/local-notifications/

しかし、それは私の場合には適用されません。

ありがとうございます!

Ivan。

答えて

0

質問がある場合は、ユーザーが指定した時間に基づいて新しいDate()オブジェクトを作成することですが、hte belowメソッドを使用してカスタム日付値を作成できます。

var d = new Date(year, month, day, hours, minutes, seconds, milliseconds); 

ご希望のものをお探しください。

LocalNotifications.schedule({ 
    text: 'Delayed ILocalNotification', 
    at: new Date(year, month, day, hours, minutes, seconds, milliseconds), 
    led: 'FF0000', 
    sound: null 
}); 
+0

興味深いことに、うまくいくはずです。しかし、私はピッカーとは別に時間と分を得る方法を知る必要があります。これを知って、私はこの情報を持つDateオブジェクトを作成することができます –

+0

これは一緒に別個の質問でなければならないかもしれません:) – Purus

+0

ありがとう、私はそれを解決しました:) –