Skip to main content
Version: v3.x

set

Start from API_LEVEL 3.0 . Please refer to API_LEVEL.

Support for persistent timers to wake up pages of Mini Program.

info

permission code: device:os.alarm

Type

function set(option: Option): Result

Parameters

Option

PropertyTypeRequiredDefaultValueDescriptionAPI_LEVEL
appidnumberN-App ID of the Mini Program, default current Mini Program ID3.0
filestringY-File path to wake up Mini Program3.0
timenumberN-Timer execution time, UTC timestamp, in seconds, this field has higher priority than delay3.0
delaynumberN-How many seconds of delay based on the current time after the execution, in seconds3.0
storebooleanNfalseDoes the timer need persistent storage (can still be executed successfully after device reboot)3.0
repeat_typenumberN-Timer repetition type, refer to timer periodic repetition constants3.0
repeat_periodnumberN-Effective when repeat_type is set to REPEAT_MINUTE, REPEAT_HOUR, REPEAT_DAY, used in conjunction with repeat_duration to set a repeat period, one repeat period in the current repeat_type, containing repeat_period times, and repeat_duration times before the reminder3.0
repeat_durationnumberN-When repeat_type is set to REPEAT_MINUTE, REPEAT_HOUR, REPEAT_DAY, the number of reminders in a period of the timer, used with repeat_duration, a period of the current repeat_type, including repeat_period times, repeat_duration times before the reminder3.0
week_daysnumberN-Effective when repeat_type is REPEAT_WEEK, you can customize which days of the week are repeated, refer to the timer week constants3.0
start_timenumberN-The time when the repeat reminder starts, in UTC seconds, and the repeat reminder only takes effect during the repeat time period3.0
end_timenumberN-The time when the repeat reminder ends, in UTC seconds, and the repeat reminder only takes effect during the repeat time period3.0

Result

TypeDescription
numberThe id returned by the timer creation, 0 is an invalid ID, which means the timer creation failed, and the ID remains the same after the system restart for timers that support persistence

Constants

Timer repeats constants

ConstantDescriptionAPI_LEVEL
REPEAT_ONCERepeat once3.0
REPEAT_MINUTERepeat once per minute3.0
REPEAT_HOURRepeat once per hour3.0
REPEAT_DAYRepeat once per day3.0
REPEAT_WEEKRepeat once per week3.0
REPEAT_MONTHRepeat once per month3.0
REPEAT_YEARRepeat once per year3.0

Timer weekly constants

ConstantDescriptionAPI_LEVEL
WEEK_MONMonday3.0
WEEK_TUETuesday3.0
WEEK_WEDWednesday3.0
WEEK_THUThursday3.0
WEEK_FRIFriday3.0
WEEK_SATSaturday3.0
WEEK_SUNSunday3.0

Example

// At a certain time each day
import { set, REPEAT_DAY } from '@zos/alarm'

const option = {
file: 'pages/index.js',
time: 12345678,
repeat_type: REPEAT_DAY,
}
const id = set(option)

// Every Monday and Wednesday
import { set, REPEAT_WEEK, WEEK_MON, WEEK_WED } from '@zos/alarm'

const option = {
file: 'pages/index.js',
time: 12345678,
repeat_type: REPEAT_WEEK,
week_days: WEEK_MON | WEEK_WED,
}
const id = set(option)

// Reminder every 21 days
import { set, REPEAT_DAY } from '@zos/alarm'

const option = {
file: 'pages/index.js',
time: 12345678,
repeat_type: REPEAT_DAY,
repeat_period: 20,
repeat_duration: 1,
}
const id = set(option)