iOS本地通知与活动视图全解析
1. UNLocationNotificationTrigger与本地通知创建
1.1 UNLocationNotificationTrigger简介
UNLocationNotificationTrigger会在用户进入或离开特定地理区域时触发通知。不过,这里我们主要通过一个时间间隔触发通知的示例来展示本地通知的创建过程。
1.2 本地通知创建示例代码
以下是创建一个本地通知的示例代码,该通知会在指定的时间间隔后触发:
let interval = // ... whatever ...
let trigger = UNTimeIntervalNotificationTrigger(
timeInterval: interval, repeats: false)
let content = UNMutableNotificationContent()
content.title = "Caffeine!"
content.body = "Time for another cup of coffee!"
content.sound = UNNotificationSound.default
content.categoryIdentifier = self.categoryIdentifier
let url = Bundle.main.url(forResource: "cup", withExtension: "jpg")!
if let att = try? UNNotificationAttachment(
ident
超级会员免费看
订阅专栏 解锁全文
460

被折叠的 条评论
为什么被折叠?



