swift - 本地通知
1.
AppDelegate 注册
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
regisigerNotification()
return true
}
//注册本地通知
private func regisigerNotification(){
// let type : [UIUserNotificationType] = [.alert, .badge, .sound]
if #available(iOS 8.0, *) {
let uns = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
UIApplication.shared.registerUserNotificationSettings(uns)
}
}
}
2. VC 使用
class ViewController: UIViewController {
@IBAction func sendNotification(_ sender: Any) {
/// 创建
let localNotification = UILocalNotification()
//设置标题
localNotification.alertBody = "通知来了"
//几秒之后执行
localNotification.fireDate = Date(timeIntervalSinceNow: 2)
//立即发送
// UIApplication.shared.presentLocalNotificationNow(localNotification)
//发送:按照设置的执行时间发送
UIApplication.shared.scheduleLocalNotification(localNotification)
}
//取消
@IBAction func cancleNotification(_ sender: Any) {
UIApplication.shared.cancelAllLocalNotifications()
}
//查看
@IBAction func viewNotification(_ sender: Any) {
print(UIApplication.shared.scheduledLocalNotifications)
}
}
也可以查看 :
https://www.cnblogs.com/Free-Thinker/p/7120211.html
swift - 本地通知的更多相关文章
- swift - 本地通知2 - 啰嗦版
1. import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var windo ...
- 如何在 iOS 8 中使用 Swift 实现本地通知(上)
当你的应用在后台运行时,可以简单地使用本地通知把信息呈现给用户.它可以允许你显示 提醒.播放提示音和数字角标(badge).本地通知可以被以下的事件触发:计划好的时间点或者用户进入和离开某个地理区域. ...
- Swift - 本地消息的推送通知(附样例)
使用UILocalNotification可以很方便的实现消息的推送功能.我们可以设置这个消息的推送时间,推送内容等. 当推送时间一到,不管用户在桌面还是其他应用中,屏幕上方会都显示出推送消息. 1, ...
- ios开发——实用技术OC-Swift篇&本地通知与远程通知详解
本地通知与远程通知详解 一:本地通知 Local Notification的作用 Local Notification(本地通知) :是根据本机状态做出的通知行为,因此,凡是仅需依赖本机状态即可判 ...
- 如何在 iOS 8 中使用 Swift 实现本地通知(下)
在上集中,我们已经构建了一个简单的待办列表应用(to-do list app),这个应用可以在待办项过期时通过本地通知提醒用户.现在,我们要在之前的基础上添加以下功能:应用图标角标上显示过期待办项的数 ...
- Swift 本地推送通知UILocalNotification
Notification是智能手机应用开发中常用的信息传递机制,它不用消耗更多资源去不停的检查信息状态,可以非常好的节省资源. 在iOS中分为两种通知:本地.远程.本地的UILocalNotifica ...
- [Xcode 实际操作]九、实用进阶-(11)系统本地通知的创建和使用
目录:[Swift]Xcode实际操作 本文将演示系统本地通知的创建和使用. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit //引入需要 ...
- UILocalNotification本地通知的使用方法
本文所写方法主要应用UILocalNotification达到本地推送通知栏信息 取消了其他教程里过期的UIAlertView方法 使用UILocalNotification主要分为创建 调用 取消 ...
- IOS 本地通知推送消息
在现在的移动设备中,好多应用性的APP都用到了推送服务,但是有好多推送的内容,比如有的只是单纯的进行推送一个闹钟类型的,起了提醒作 用,有的则是推送的实质性的内容,这就分为推送的内容来区别用什么推送, ...
随机推荐
- block原理
block原理 block的本质是一个结构体,包含引用的外部变量及一个需要执行的函数的函数指针,在内存中可以有三个位置,即堆上.栈上和全局区(静态区).当block中没有引用外部变量时,block的位 ...
- redis 学习笔记1(安装以及控制台命令)
为什么要学习这个? 分布式技术必会,得益于redis的设计理念,内存数据库,epoll(多路复用)模型,单线程模型除去了锁和上下文切换,提高了性能.单线程保证执行顺序(轮询),在分布式环境下对于数据的 ...
- css:自己实现一个带小图标的input输入框
有小图标的input输入框<input type="text" placeholder="输入手机号" style="background:ur ...
- centos7启动iptables时报Job for iptables.service failed because the control process exited with error cod
centos7启动iptables时报Job for iptables.service failed because the control process exited with error cod ...
- mongoDB如何处理多对多关系
问题描述: 例如在关系数据库中有一个Team表,一个User表,两者是多对多的关系,即一个Team可以有多个User,一个User也可能属于多个Team,请问这样的关系在MongoDB中如何存储? 如 ...
- 吴裕雄 python oracle检索数据(2)
import cx_Oracle conn = cx_Oracle.connect("scott/admin@localhost:1521/orcl")cursor = conn. ...
- 吴裕雄 25-MySQL 临时表
MySQL 临时表MySQL 临时表在我们需要保存一些临时数据时是非常有用的.临时表只在当前连接可见,当关闭连接时,Mysql会自动删除表并释放所有空间.临时表在MySQL 3.23版本中添加,如果你 ...
- git 分支合并develop 重新拉取
1.本地包 zb-local 上传到对应的线上分支 zb-online cd 进入本地所在文件夹,然后执行下面三项 git add . git commit -m '修改' git push 或者 ...
- python字典dict的成对运算
dict = {'age': 18, 'name': 'jin', 'sex': 'male', }# for k,v in dict.items():# print(k,v)# v1 = dict[ ...
- python字典dict的增、删、改、查操作
## python字典dict的增.删.改.查操作dict = {'age': 18, 'name': 'jin', 'sex': 'male', }#增# dict['heigh'] = 185 # ...