本地通知 UILocalNotification
2015-08-06 00:00
162 查看
发送一个本地通知
取消本地通知
在接到通知时调用的方法
// MARK:本地推送 func sendNotification(time: Double, title: String, remindId: NSNumber) { var notification = UILocalNotification() notification.fireDate = NSDate(timeIntervalSinceNow: time) notification.timeZone = NSTimeZone.systemTimeZone() notification.soundName = UILocalNotificationDefaultSoundName notification.alertBody = title /* 给通知加上标识, * 1.方便在接到对应通知时做出相应操作 * 2.方便在想要取消该通知时,找到该通知 */ var infoDictionary = NSMutableDictionary(objects: [notifiName, remindId], forKeys: ["localKey", "remindId"]) notification.userInfo = infoDictionary UIApplication.sharedApplication().scheduleLocalNotification(notification) }
取消本地通知
func deleteLocalNotification(NSNumber: id) { var array = UIApplication.sharedApplication().scheduledLocalNotifications as NSArray if array.count > 0 { for var i = 0; i < array.count; i++ { var myLocalNot = array[i] as UILocalNotification //获取通知 var info = myLocalNot.userInfo! as NSDictionary //获取通知的userInfo var remindId = info.objectForKey("remindId") as NSNumber//获取通知的标识 if id == remindId { UIApplication.sharedApplication().cancelLocalNotification(myLocalNot) break } } } }
在接到通知时调用的方法
//在接到通知时,appdelegate会调用该方法 func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) { }
相关文章推荐
- mysql数据库unique索引的添加与删除
- iOS开发--设置UIButton
- 2、快速排序(QuickSort)-C#实现
- uinavigationController和uiSrcoll以及uiPageControl的结合使用---小相册
- 利用uinavigattion实现简单的登陆界面
- Codeforces Round #250 (Div. 1) D. The Child and Sequence(线段树暴力)
- WPF QuickStart系列
- WPF QuickStart系列之附加属性(Attached Property)
- 利用AutoLayout uilabel文字自动适应大小,宽度
- UINavigationController
- 定制自己的Request
- HDU 4372 Count the Buildings(组合数学,第一类Stirling数)
- LIS UVA 10534 Wavio Sequence
- (一〇九)UIButton的使用技巧 -imageView、titleLabel、圆角等
- (一〇九)UIButton的使用技巧 -imageView、titleLabel、圆角等
- UIImagePickerController详解
- iOS开发--UILineBreakModeWordWrap deprecated
- UI中控件的应用
- ios8 UITableView设置 setSeparatorInset:UIEdgeInsetsZero不起作用的解决办法
- SPOJ--K-query (线段树离线) 离线操作解决一些问题