Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在每月的第一天重复本地通知-swift_Swift_Xcode_Usernotifications - Fatal编程技术网

如何在每月的第一天重复本地通知-swift

如何在每月的第一天重复本地通知-swift,swift,xcode,usernotifications,Swift,Xcode,Usernotifications,我想知道如何在每个月的第一天以swift的形式发出本地通知。所以在1月1日,提醒一下。在2月1日,同样的提醒,等等。最好使用日期组件 首先,我们需要获得默认的“UNUserNotificationCenter” 创建“未通知内容” 创建“UNCalendarNotificationTrigger” 创建“UNNotificationRequest” 将“UNNotificationRequest”添加到“UNUserNotificationCenter” 用户可以参考此详细信息。@Evac re

我想知道如何在每个月的第一天以swift的形式发出本地通知。所以在1月1日,提醒一下。在2月1日,同样的提醒,等等。最好使用日期组件

  • 首先,我们需要获得默认的“UNUserNotificationCenter”
  • 创建“未通知内容”
  • 创建“UNCalendarNotificationTrigger”
  • 创建“UNNotificationRequest”
  • 将“UNNotificationRequest”添加到“UNUserNotificationCenter”

  • 用户可以参考此详细信息。

    @Evac repeats标志在UNCalendarNotificationTrigger right?中设置为true?。所以我想应该重复一遍。您可以通过在iPhone中手动更改日期来测试这一点。
    let center =  UNUserNotificationCenter.current()
    
    //create the content for the notification
    let content = UNMutableNotificationContent()
    content.title = " Title"
    content.subtitle = "SubTitle"
    content.body = "jvsvsvasvbasbvfasfv"
    content.sound = UNNotificationSound.default
    
    var dateComp = DateComponents()
    dateComp.month = 1;
    dateComp.day = 1;
    dateComp.hour = 00;
    dateComp.minute = 00;
    
    let trigger = UNCalendarNotificationTrigger(dateMatching: dateComp, repeats: true)
    
    //create request to display
    let request = UNNotificationRequest(identifier: "ContentIdentifier", content: content, trigger: trigger)
    
    //add request to notification center
    center.add(request) { (error) in
        if error != nil {
            print("error \(String(describing: error))")
        }
    }