离子2中的提醒/报警

时间:2017-01-05 06:18:52

标签: android cordova ionic-framework ionic2 reminders

我试图在一段时间后在ionic2中实现提醒/警报。我已经找到了这个插件https://github.com/wnyc/cordova-plugin-wakeuptimer但是我想用typescript来实现它,因为这不能识别window.wakeuptimer在下面使用提到的代码:

window.wakeuptimer.wakeup( successCallback,  
   errorCallback, 

   // a list of alarms to set

   {

        alarms : [{

            type : 'onetime',

            time : { hour : 14, minute : 30 },

            extra : { message : 'json containing app-specific information to be posted when alarm triggers' }, 

            message : 'Alarm has expired!'

       }] 

   }

); 

任何人都可以帮助我吗

2 个答案:

答案 0 :(得分:6)

您尝试使用的插件已有近3年的历史。比离子2本身更老。您应该查看https://ionicframework.com/docs/v2/native/

中列出的本机插件

过去,我使用本地通知插件(https://ionicframework.com/docs/v2/native/local-notifications/)来处理提醒/闹钟。

计划非常简单,您只需要为要通知的时间创建一个Date对象。以下是使用您提供的数据的示例:

import { LocalNotifications } from 'ionic-native';


// Schedule delayed notification 

LocalNotifications.schedule({
   text: 'Alarm has expired!',
   at: new Date(new Date().getTime() + 3600),
   sound: isAndroid ? 'file://sound.mp3': 'file://beep.caf',
   data: { message : 'json containing app-specific information to be posted when alarm triggers' }
});

答案 1 :(得分:0)

要重复触发它,可以使用以下代码。它将每天触发通知。 Reference

    const deviceName = 'Sensor1'
    
    // Create the thingShadow object with argument data
    const device = awsIoT.device({
       keyPath: 'private.pem.key',
       certPath: 'certificate.pem.crt',
       caPath: '/home/ec2-user/environment/root-CA.crt',
       clientId: deviceName,
       host: endpointFile.endpointAddress
    });
相关问题