1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  2. {
  3.  
  4. UILocalNotification *notification = [[UILocalNotification alloc] init];
  5.  
  6. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  7. [formatter setDateFormat:@"HH:mm:ss"];
  8. // 触发通知的时间
  9. NSDate *now = [formatter dateFromString:@"15:04:00"];
  10. notification.fireDate = now;
  1. // 触发通知的时间
  2. NSDate *currDate = [NSDate date];
  3. NSTimeInterval interval = *; // 半个小时
  4. NSDate *after30minDate = [currDate initWithTimeIntervalSinceNow:+interval];
  5. NSString *currTime = [formatter stringFromDate:after30minDate];
  6.  
  7. NSDate *notificationTme = [formatter dateFromString:currTime];
  8. notification.fireDate = notificationTme;
  9.  
  10. notification.fireDate = [currDate dateByAddingTimeInterval:];
  1.  
  1. // 设置时区,默认即可
  2. notification.timeZone=[NSTimeZone defaultTimeZone];
  3. // 通知重复提示的单位,可以是天、周、月
  4. notification.repeatInterval = NSDayCalendarUnit;
  5. // 通知内容
  6. notification.alertBody = @"这是一个新的通知";
  7. // 通知被触发时播放的声音
  8. notification.soundName = UILocalNotificationDefaultSoundName;
  9. // 设置IconBadgeNumber
  10. notification.applicationIconBadgeNumber = [[[UIApplication sharedApplication] scheduledLocalNotifications] count]+;
  11. // 设置本地通知发送的消息,这个消息可以接受
  12. NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"setNotificationForEveryDay", @"key", nil];
  13. notification.userInfo = infoDict;
  14. //执行通知注册
  15. [[UIApplication sharedApplication] scheduleLocalNotification:notification];
  16. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  17. // Override point for customization after application launch.
  18. self.window.backgroundColor = [UIColor whiteColor];
  19. [self.window makeKeyAndVisible];
  20. return YES;
  21. }
  22.  
  23. // 应用收到通知时,会调到下面的回调函数
  24. - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
  25. {
  26. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"LocalNotification" message:notification.alertBody delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
  27. [alert show];
  28.  
  29. //这里可以接受到本地通知中心发送的消息
  30. NSDictionary* dic = notification.userInfo;
  31.  
  32. // 图标上的数字减1
  33. application.applicationIconBadgeNumber -= ;
  34.  
  35. NSLog(@"user info = %@",[dic objectForKey:@"key"]);
  36. }

UILocalNotification的更多相关文章

  1. iOS调试通过UILocalNotification或RemoteNotification启动的app

    相信很多同学都为调试苹果的通知烦恼过,特别是通过通知启动app这个功能,简直让人欲哭无泪!!! 然而我们都遇到的问题,苹果怎么可能没有想到,原来早就有了官方的解决办法,只是我们不知道而已... 这次又 ...

  2. 用UILocalNotification实现一个闹钟(Swift)

    之前项目需求要实现一个闹钟,github上找了半天发现都是很旧的代码了,所以就准备自己写一个,刚好最近在学习Swift,就用Swift写了一个demo放在这里:https://github.com/P ...

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

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

  4. 本地推送UILocalNotification

    //本地推送---无需网络,由本地发起 UILocalNotification *localNotification = [[UILocalNotification alloc]init]; //设置 ...

  5. ios 把已经点击过的UILocalNotification 从系统的通知中心现实中移除

    在ios7 上一个uilocalnotification在中心现实后,点击该消息,程序被唤醒了,但是该通知没有被移除.用了以下的代码后可以解决这个问题         UIApplication.sh ...

  6. iOS UILocalNotification 每2周,每两个月提醒

    iOS 的UILocalNotification提醒提供了默认的重复频率,比如,一天,一个星期等等,但是对于非标准的频率,比如每,2周,每2个月,无法重复提醒. 我们的思路是在应用程序开始时,把即将发 ...

  7. iOS - iPhone开发 UILocalNotification的使用

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

  8. Swift - 推送之本地推送(UILocalNotification)添加Button的点击事件

    上一篇讲到的本地推送是普通的消息推送,本篇要讲一下带按钮动作的推送消息 import UIKit @UIApplicationMain class AppDelegate: UIResponder, ...

  9. Swift - 推送之本地推送(UILocalNotification)

    // 本地推送通知是通过实例化UILocalNotification实现的.要实现本地化推送可以在AppDelegate.swift中添加代码实现,本事例是一个当App进入后台时推送一条消息给用户. ...

  10. ios推送:本地通知UILocalNotification

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

随机推荐

  1. POI导入数据

    package util; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.I ...

  2. Handler消息机制实现更新主UI

    如下实现的是简单的更新主UI的方法,用Handler消息机制 将textview的内容每隔一秒实现num++ /* * handler消息机制 * asynctask异步任务 *  * httpcli ...

  3. linux下部署svn服务器

    系统Linux debian 2.6.32-5-686 先安装svn工具:apt-get install subversion,耐心等待安装完成.安装完成后svn客户端.服务器都有了. 接者建立svn ...

  4. python标准库 platform模块

    # -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #platform #作用:检查底层平台硬件,操作系统和解释器版本信 ...

  5. Oracle 更改用户名

    直接更改系统user$表中的用户名. 查询要更改的用户名 SQL> select user#,name,password from user$ where name ='TICKETS'; US ...

  6. AJAX 控件集之TextBoxWatermark(水印文本框)控件

    功能:       可以让TextBox控件初始化的时候拥有水印文字.属性:    TargetControlID :要使用具有水印效果的TextBox控件ID.    WatermarkCssCla ...

  7. 使用安卓中的TextToSpeech控件实现朗读文字

    首先感谢原文的博主,本文中的代码均来自该博主:(原文地址)http://flycatdeng.iteye.com/blog/1827245 朗读文字不需要任何的权限,这个控件的好处是首先不要权限,其次 ...

  8. 我跟着siki学Unity3D游戏开发——PongGame

    一.屏幕坐标转换为世界坐标. 1.游戏逻辑,根据界面布局,将墙体控制到对应的位置: vector3 position=Camer.main.ScreenToWorldPoint(new vetor2( ...

  9. MFC串口通信

    1.串口的操作可以有两种操作方式:同步操作方式和重叠操作方式(又称为异步操作方式). 同步操作时,API函数会阻塞直到操作完成以后才能返回(在多线程方式中,虽然不会阻塞主线程,但是仍然会阻塞监听线程) ...

  10. n个数的最大公约、最小公倍数

    #include <cstdio> #include <cstring> using namespace std; #define N 1010 //两个数的最大公约数和最小公 ...