Skip to main content
Version: v3+

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
urlstringY-File path to wake up Mini Program, supporting App Service3.0
timenumberN-Timer execution time, UTC timestamp, in seconds, this field has higher priority than delay, each call must pass one of the time and delay parameter3.0
delaynumberN-How many seconds of delay based on the current time after the execution, in seconds. Each call must pass one of the time and delay parameter3.0
paramstringN-The argument passed to the app.js lifecycle onCreate3.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_periodnumberNREPEAT_MINUTEEffective 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_durationnumberN1When 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_MINUTESpecify the repetition period as minute3.0
REPEAT_HOURSpecify the repetition period as hour3.0
REPEAT_DAYSpecify the repetition period as day3.0
REPEAT_WEEKSpecify the repetition period as week3.0
REPEAT_MONTHSpecify the repetition period as month3.0
REPEAT_YEARSpecify the repetition period as 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 = {
url: '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 = {
url: '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 = {
url: 'pages/index.js',
time: 12345678,
repeat_type: REPEAT_DAY,
repeat_period: 20,
repeat_duration: 1,
}
const id = set(option)