小编nsd*_*d32的帖子

为什么只调用我的上一个本地通知功能?

我对swift很新,我正在尝试调用多个函数来请求UISwitch IBAction中的本地通知.我想在某个日期发送通知 - 一年中的每个季度在第4,7,10,1个月.只有第四季度的功能才被调用.如何调用所有四个函数?这是我的代码:

// UISwitch用于季度通知

@IBAction func quarterlyFrequencyTapped(_ sender: UISwitch) {

if quarterlyFrequency.isOn == true {

    firstQuarter(); secondQuarter(); thirdQuarter(); fourthQuarter()

    print("quarterly frequency is \(quarterlyFrequency.isOn)")

} else {

    removeQuarterlyNotification()

    print("quaterly frequency is \(monthlyFrequency.isOn)")

       }

}
Run Code Online (Sandbox Code Playgroud)

//所有四个季度的功能

func firstQuarter() {
    let firstQuarterContent = UNMutableNotificationContent()
    firstQuarterContent.title = "First Quarter"
    firstQuarterContent.subtitle = "Some string"
    firstQuarterContent.body = "Some other string"

    var firstQuarterDate = DateComponents()
    firstQuarterDate.month = 3
    firstQuarterDate.day = 11
    firstQuarterDate.hour = 19
    firstQuarterDate.minute = 20

    let firstQuarterTrigger = UNCalendarNotificationTrigger(dateMatching: firstQuarterDate, repeats: true)
    let …
Run Code Online (Sandbox Code Playgroud)

notifications swift usernotifications

4
推荐指数
1
解决办法
470
查看次数

标签 统计

notifications ×1

swift ×1

usernotifications ×1