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都用到了推送服务,但是有好多推送的内容,比如有的只是单纯的进行推送一个闹钟类型的,起了提醒作 用,有的则是推送的实质性的内容,这就分为推送的内容来区别用什么推送, ...
随机推荐
- MYSQL数据库中,常见的数据类型有哪些?它们与java中的数据类型如何对应
A.常规 映射 integer 或者 int int 或者 java.lang.Integer INTEGER 4 字节 long long Long BIGINT 8 字节 short short ...
- Android 性能优化 SparseArray【转载】
原文地址:Android学习笔记之性能优化SparseArray 学习内容: 1.Android中SparseArray的使用.. 昨天研究完横向二级菜单,发现其中使用了SparseArray去替 ...
- 多线程 Runnable 实现线程 内部类
public class ThreadDemo4 { public static void main(String[] args){ System.out.println(Thread.current ...
- week05 05restful api
和第一个项目一样 然后去App.js注册一下 但是呢 新闻是写死在 现在主要输调通前端client和后端server 持续获取新闻 至于真假先不考虑 下面我们回到前端NewsPanel 这个reque ...
- Hibernate 再接触 关系映射 一对一单向外键关联
对象之间的关系 数据库之间的关系只有外键 注意说关系的时候一定要反面也要说通 CRUD 数据库之间设计 主键关联 单向的外键关联 中间表 一对一单向外键关联 Husband.java package ...
- 学JS的心路历程-for of和for in
我们在刚入门JS时候,说到要跑出数组的每个值肯定都是这样子: var arr = [1,2,3,4,5,6]: for(let i = 0:i < arr.length:i++){ consol ...
- NTKO OFFICE文档控件
目录 前言 什么是ntko 准备工作 实战演练 总结 一.前言 Web开发中经常需要用到在线处理office文档的功能,现在市面上有一些常用的Web页面调用显示Office的控件技术,用起来很方便. ...
- jquery 中attr()的一个用法
html 如下: <ul><li><img src="./img/addface_icon.png" alt="">< ...
- 1.3.7、CDH 搭建Hadoop在安装之前(端口---第三方组件使用的端口)
第三方组件使用的端口 在下表中,每个端口的“ 访问要求”列通常是“内部”或“外部”.在此上下文中,“内部”表示端口仅用于组件之间的通信; “外部”表示该端口可用于内部或外部通信. Component ...
- msf客户端渗透(二):PDF漏洞、恶意网站、flash漏洞、IE漏洞、java漏洞、android漏洞、VBScript感染payload
这个漏洞利用只在XP上有效 利用pdf漏洞利用payload exploit生成一个pdf文件 传到被攻击机上 启动msf侦听 exploit -j XP上双击运行这个pdf时,kali获取到一个sh ...