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都用到了推送服务,但是有好多推送的内容,比如有的只是单纯的进行推送一个闹钟类型的,起了提醒作 用,有的则是推送的实质性的内容,这就分为推送的内容来区别用什么推送, ...
随机推荐
- DRM in Android
我们Tieto公司的MM专家在<程序员>第8期上发表了一篇关于DRM的文章,请大家指教. DRM in Android DRM,英文全称为Digital Rights Management ...
- mysql中不同事务隔离级别下数据的显示效果--转载
事务是一组原子性的SQL查询语句,也可以被看做一个工作单元.如果数据库引擎能够成功地对数据库应用所有的查询语句,它就会执行所有查询,如果任何一条查询语句因为崩溃或其他原因而无法执行,那么所有的语句就都 ...
- 深入探索 Java 热部署--转
在 Java 开发领域,热部署一直是一个难以解决的问题,目前的 Java 虚拟机只能实现方法体的修改热部署,对于整个类的结构修改,仍然需要重启虚拟机,对类重新加载才能完成更新操作.本文将探索如何在不破 ...
- ifndef/define/endif 的作用
转载自百度百科 ,感谢度娘 1 2 3 #ifdef语句1 //程序2 #endif 可翻译为:如果宏定义了语句1则执行程序2. 作用:我们可以用它区隔一些与特定头文件.程序库和其他文件版本有关的代码 ...
- 分享一个字数限制和统计的UITextView分类方法
- (NSUInteger)letterCountWithLimits:(NSInteger)limits { NSString *toBeString = self.text; NSUInteger ...
- 万能的Entry,两个变量的Model/JavaBean再也不用写了!
前言 很多时候传数据需要只含两个变量的Model/JavaBean,但就为了两个变量去写一个Model/JavaBean实在是麻烦,而且类型固定重用性低.比如: 1.网格显示的头像-名称 需要 Str ...
- cxf
一,cxf webService入门案例 1,jar包 注意版本 使用jdk6和apache-cxf-3.1.2,但cxf-3.1.2已经不支持jdk6,需要jdk7以上 版本用错会报java.lan ...
- jemalloc源码结构分析(一):内存申请处理过程
一.5种malloc方法 1)tcache_alloc_small 2)arena_malloc_small 3)tcache_alloc_large 4)arena_malloc_large 5)h ...
- centos7支持ntfs
简单搜索了一下,发现一个很好的安装步骤,简洁有效,已经试验. rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release- ...
- (原创)fedora 17安装KVM虚拟机
1.安装KVM yum groupinstall Virtualization 'Virtualization Client' 2.安装api支持 yum install libvirt servic ...