UILocalNotification本地通知
// 执行通知一定要退出应用或挂起应用(进入后台)才能收到通知。
1、在iOS8及其以后版本中使用本地消息需要先获得用户的许可,否则无法成功注册本地消息。因此,我们将询问用户许可的代码片段添加到了app启动后的入口方法中(AppDelegate中的didFinishLaunchingWithOptions)
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
var version=UIDevice.currentDevice().systemVersion
if (version as NSString).floatValue>=8.0{
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, categories: nil))
}
self.window=UIWindow(frame: UIScreen.mainScreen().bounds)
self.window!.backgroundColor=UIColor.whiteColor()
self.window!.makeKeyAndVisible()
self.window!.rootViewController=TB_Home()
return true
}
2、发送通知
func sendLocalNotification(){
//创建本地通知
var notification=UILocalNotification()
//通知触发时间(10秒后触发)
notification.fireDate=NSDate(timeIntervalSinceNow: )
//通知时区(使用本地时区)
notification.timeZone=NSTimeZone.defaultTimeZone()
//通知提示标题(如果不写默认是App的名称)
notification.alertTitle="messageTitle"
//通知提示内容
notification.alertBody="messageBody"
//通知提示音(使用默认的通知提示音)
notification.soundName=UILocalNotificationDefaultSoundName
//应用程序右上角显示的数字+1
notification.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber+
//启动这个通知
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
3、进入前台,清除右上角图标及当前应用所有通知
func applicationWillEnterForeground(application: UIApplication) {
application.applicationIconBadgeNumber= //程序右上角图标设置0
application.cancelAllLocalNotifications() //清除当前应用所有通知
}
UILocalNotification本地通知的更多相关文章
- UILocalNotification本地通知的使用方法
本文所写方法主要应用UILocalNotification达到本地推送通知栏信息 取消了其他教程里过期的UIAlertView方法 使用UILocalNotification主要分为创建 调用 取消 ...
- iOS开发中UILocalNotification本地通知实现简单的提醒功能
这段时间项目要求做一个类似的闹钟提醒功能,对通知不太熟悉的我,决定先用到xcode自带的本地通知试试,最终成功的实现了功能,特整理分享下. 它的表现特点: app关闭的时候也能接收和显示通知. app ...
- ios推送:本地通知UILocalNotification
Notification是智能手机应用编程中非常常用的一种传递信息的机制,而且可以非常好的节省资源,不用消耗资源来不停地检查信息状态(Pooling),在iOS下应用分为两种不同的Notificati ...
- IOS本地通知:UILocalNotification使用记录
第一次接触IOS的本地通知的使用,看到别人写的一个比较详细的记录,自己整理过来,方便以后再次使用和拓展: 1.创建一个本地通知,添加到系统: // 初始化本地通知对象 UILocalNotificat ...
- IOS 本地通知 UILocalNotification
IOS 本地通知 UILocalNotification [本文章第四部分中的代码逻辑来自网上的借鉴,并非我自己原创] 大概一个月前,我开始跟着做IOS项目了.学习C++,了解Objective-C, ...
- 本地通知UILocalNotification
1.增加一个本地推送 //设置20秒之后 ]; //chuagjian一个本地推送 UILocalNotification *noti = [[[UILocalNotification alloc] ...
- Ios开发中UILocalNotification实现本地通知实现提醒功能
这两天在做一个日程提醒功能,用到了本地通知的功能,记录相关知识如下: 1.本地通知的定义和使用: 本地通知是UILocalNotification的实例,主要有三类属性: scheduled time ...
- 本地通知-UILocalNotification
第一步:创建本地推送 本地通知 UILocalNotification // 创建⼀一个本地推送 UILocalNotification * notification = [[UILocalNotif ...
- IOS 本地通知推送消息
在现在的移动设备中,好多应用性的APP都用到了推送服务,但是有好多推送的内容,比如有的只是单纯的进行推送一个闹钟类型的,起了提醒作 用,有的则是推送的实质性的内容,这就分为推送的内容来区别用什么推送, ...
随机推荐
- opencv中的基本拼接
普通版的图像拼接,事实上非常简单并且效果不很差. 实现方式: 新建工程: 去opencv里面[f:\opencv249\opencv\sources\samples\cpp]把stitching.cp ...
- visibility,display区别
visibility:hidden,display:none 前者隐藏位置还在,后者隐藏位置消失
- c语言面试题之sizeof
c语言面试题之sizeof */--> c语言面试题之sizeof Table of Contents 1. sizeof 1 sizeof sizeof是c语言中判断数据类型或者表达式的长度符 ...
- CentOS 6.x安装gcc 4.8/4.9/5.2
1.gcc 4.8 cd /etc/yum.repos.d wget http://people.centos.org/tru/devtools-2/devtools-2.repo -gcc -bin ...
- Python 基础【第八篇】变量
1.变量定义: 给数据进行命名,数据的名字就叫做变量 2.变量格式: [变量名] = [值] 注:变量名命名需要满足下面两条准则 准则一:标示符开头不能为数字.不能包含空格.特殊字符准则二:标示符不能 ...
- css动画——transition和animation
http://www.ruanyifeng.com/blog/2014/02/css_transition_and_animation.html 第一部分:CSS Transition 在CSS 3引 ...
- Leetcode 104. Maximum Depth of Binary Tree(二叉树的最大深度)
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- map 树木品种
树木品种 TimeLimit: 1 Second MemoryLimit: 32 Megabyte Totalsubmit: 517 Accepted: 120 Description 硬木是 ...
- 读jQuery官方文档:遍历
遍历 jQuery的快捷遍历方法可以快速定位到想要的元素.查找祖先元素 html<div class="grandparent"> <div class=&quo ...
- 基于mvc结构的前端页面框架搭建
前端开发一年了,向大家交流下自己实践总结下来的一点点开发心得.人生难免磕磕碰碰,前进的道路很多,在学习工作上我们都得学会如何让自己过的更高效,代码亦是如此. 下面,开始介绍自己总结的前端框架搭建(布局 ...