This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 創建觸發條件,這裡是設定每天8:30 | |
var date = DateComponents() | |
date.hour = 8 | |
date.minute = 30 | |
let trigger = UNCalendarNotificationTrigger(dateMatching: date, repeats: true) | |
// 創建觸發條件,這裡是設定座標經緯度 | |
let center = CLLocationCoordinate2D(latitude: 37.335400, longitude: -122.009201) | |
let region = CLCircularRegion(center: center, radius: 2000.0, identifier: "Headquarters") | |
region.notifyOnEntry = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1.創建通知內容 | |
let content = UNMutableNotificationContent() | |
content.title = "我是標題" | |
content.subtitle = "我是副標題" | |
content.body = "我是內容" | |
// 2.創建觸發條件,這裡是設定5秒後發出通知且不重複,注意這裡不能設定60秒內重複,會crash | |
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false) | |
// 3.請求標示符 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UserNotifications |