// 执行通知一定要退出应用或挂起应用(进入后台)才能收到通知。

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本地通知的更多相关文章

  1. UILocalNotification本地通知的使用方法

    本文所写方法主要应用UILocalNotification达到本地推送通知栏信息 取消了其他教程里过期的UIAlertView方法 使用UILocalNotification主要分为创建 调用 取消 ...

  2. iOS开发中UILocalNotification本地通知实现简单的提醒功能

    这段时间项目要求做一个类似的闹钟提醒功能,对通知不太熟悉的我,决定先用到xcode自带的本地通知试试,最终成功的实现了功能,特整理分享下. 它的表现特点: app关闭的时候也能接收和显示通知. app ...

  3. ios推送:本地通知UILocalNotification

    Notification是智能手机应用编程中非常常用的一种传递信息的机制,而且可以非常好的节省资源,不用消耗资源来不停地检查信息状态(Pooling),在iOS下应用分为两种不同的Notificati ...

  4. IOS本地通知:UILocalNotification使用记录

    第一次接触IOS的本地通知的使用,看到别人写的一个比较详细的记录,自己整理过来,方便以后再次使用和拓展: 1.创建一个本地通知,添加到系统: // 初始化本地通知对象 UILocalNotificat ...

  5. IOS 本地通知 UILocalNotification

    IOS 本地通知 UILocalNotification [本文章第四部分中的代码逻辑来自网上的借鉴,并非我自己原创] 大概一个月前,我开始跟着做IOS项目了.学习C++,了解Objective-C, ...

  6. 本地通知UILocalNotification

    1.增加一个本地推送 //设置20秒之后  ]; //chuagjian一个本地推送 UILocalNotification *noti = [[[UILocalNotification alloc] ...

  7. Ios开发中UILocalNotification实现本地通知实现提醒功能

    这两天在做一个日程提醒功能,用到了本地通知的功能,记录相关知识如下: 1.本地通知的定义和使用: 本地通知是UILocalNotification的实例,主要有三类属性: scheduled time ...

  8. 本地通知-UILocalNotification

    第一步:创建本地推送 本地通知 UILocalNotification // 创建⼀一个本地推送 UILocalNotification * notification = [[UILocalNotif ...

  9. IOS 本地通知推送消息

    在现在的移动设备中,好多应用性的APP都用到了推送服务,但是有好多推送的内容,比如有的只是单纯的进行推送一个闹钟类型的,起了提醒作 用,有的则是推送的实质性的内容,这就分为推送的内容来区别用什么推送, ...

随机推荐

  1. 手动开启tomacat服务器

    四.配置Tomcat环境变量 1,新建变量名(关键,你的tomacat安装目录):CATALINA_BASE,变量值:E:\apache-tomcat-6.0.37 2,新建变量名(关键,你的toma ...

  2. A+B Problem III

    描述 求A+B是否与C相等. 输入 T组测试数据. 每组数据中有三个实数A,B,C(-10000.0<=A,B<=10000.0,-20000.0<=C<=20000.0) 数 ...

  3. MySQL(16):Select-union(联合查询)

    1. Select-union(联合查询) union用于把来自许多SELECT语句的结果组合到一个结果集合中. 用法: SELECT ...UNION [ALL | DISTINCT]SELECT ...

  4. svn管理代码在cornerstone上无法添加.a 静态库文件

    有时候.a静态库不能上传到svn的服务器  导致别人拉代码运行不了 这是因为cornerstone设置里面默认不会提交.a文件, 在上图选项栏里是cornerstone默认忽略上传的文件名后缀,在这里 ...

  5. 深入理解计算机系统第二版习题解答CSAPP 2.17

    假设w=4,我们能给每个可能的十六进制数字赋予一个数值,假设用一个无符号或者补码表示.完成下表: x 无符号(B2U(x)) 补码(B2T(x)) 十六进制 二进制 0xE 1110 14 -2 0x ...

  6. 深入理解计算机系统第二版习题解答CSAPP 2.13

    从20世纪70年代末到80年代末,Digital Equipment的VAX计算机是一种非常流行的机型.它没有布尔运算AND和OR指令,只有bis(位设置)和bic(位清除)这两种指令.两种指令的输入 ...

  7. 深入理解计算机系统第二版习题解答CSAPP 2.10

    对于任一位向量a,有a ^ a = 0.考虑下面的程序: void inplace_swap(int *x, int *y) { *y = *x ^ *y; *x = *x ^ *y; *y = *x ...

  8. Java序列化接口的作用总结

    一个对象有对应的一些属性,把这个对象保存在硬盘上的过程叫做”持久化”. 把堆内存中的对象的生命周期延长,存入硬盘,做持久化操作.当下次再需要这个对象的时候,我们不用new了,直接从硬盘中读取就可以了. ...

  9. MySQL 에서 root 암호 변경하기

    먼저 터미널이나 SSH를 이용해 접속합니다. 그리고 리눅스 쉘상에서 다음과 같이 입력합니다. [mysqladmin을 이용한 암호변경] 형식) root계정]$mysqladmin -u ...

  10. react 全局面包屑

    renderBreadcrumb() { const {routes} = this.props; const items = routes.map((route, idx) => { let ...