iOS本地推送通知的基本使用

本文介绍了iOS10以前使用`UILocalNotification`创建本地通知的步骤,包括设置触发时间、标题、内容以及应用程序处理通知的方法。对于iOS10及以上版本,文章详细讲解了如何利用`UNNotificationRequest`创建本地通知,包括请求授权、创建通知内容和触发器,并提到了通知触发器的各种类型。同时,还涵盖了通知的常见属性如子标题和应用程序图标上的数字标记。
摘要由CSDN通过智能技术生成

iOS10以前本地通知(UILocalNotification)

使用步骤:

  1. 创建一个UILocalNotification对象
  2. 设置触发时间及标题、内容
  3. 注册并安排通知
// 1. 创建一个UILocalNotification对象
let localNotification = UILocalNotification()

// 2. 设置触发时间及标题、内容
localNotification.fireDate = Date(timeIntervalSinceNow: 3)
localNotification.alertTitle = "Title"
localNotification.alertBody = "alertBodyalertBodyalertBodyalertBody"

// 0. 注册通知(一般在程序刚启动时注册通知)
UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.badge, .alert, .sound], categories: nil))

// 3. 安排通知
UIApplication.shared.scheduleLocalNotification(localNotification)
  • UILocalNotification的其他属性
    • applicationIconBadgeNumber :应用程序图标上的数字标记
    • repeatInterval :重复间隔(按照年、月、日、时、分重复)
    • soundName :发出通知时的提示音,使用UILocalNotificationDefaultSoundName或者指定的音频文件名
    • userInfo :与通知相关的额外的字典,用户在通知上看不到此数据
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值