发送通知:

UILocalNotification *newNotification = [[UILocalNotification alloc] init];

if (newNotification) {

//时区

newNotification.timeZone=[NSTimeZone defaultTimeZone];

//推送事件---10秒后

newNotification.fireDate=[[NSDate date] dateByAddingTimeInterval:10];

//推送内容

newNotification.alertBody = @"信号报警";

//应用右上角红色图标数字

newNotification.applicationIconBadgeNumber = 1;

注:

//1:格式一定要支持播放,常用的格式caf

//2:音频播放时间不能大于30秒

//3:在Resource里要找到音频文件,倒入时最好能点项目名称右键add导入

newNotification.soundName = @"jingBao2.caf";

//设置按钮

newNotification.alertAction = @"关闭";

//判断重复与否

newNotification.repeatInterval = NSWeekCalendarUnit;

//存入的字典,用于传入数据,区分多个通知

NSMutableDictionary *dicUserInfo = [[NSMutableDictionary alloc] init];

[dicUserInfo setValue:@"" forKey:@"clockID"];

float floatHeng = userLocation.location.coordinate.latitude;

float floatShu = userLocation.location.coordinate.longitude;

[dicUserInfo setValue:[NSString stringWithFormat:@"%f",strX] forKey:@"heng"];

[dicUserInfo setValue:[NSString stringWithFormat:@"%f",strY] forKey:@"shu"];

newNotification.userInfo = [NSDictionary dictionaryWithObject:dicUserInfo forKey:@"dictionary"];

[dicUserInfo release];

[[UIApplication sharedApplication] scheduleLocalNotification:newNotification];

}

NSLog(@"Post new localNotification:%@", newNotification);

[newNotification release];

[pool release];

取消通知:

通知完一定要取消,IOS最多允许最近本地通知数量是64个,超过限制的本地通知将被忽略。

1:删除应用所有通知

[[UIApplication sharedApplication] cancelAllLocalNotifications];

2:根据字典删除个别通知

key:发送通知时候传入的字典值来判断是哪个推送

for (int i=0; i<[myArray count]; i++) {

UILocalNotification    *myUILocalNotification=[myArray objectAtIndex:i];

if ([[[myUILocalNotification userInfo] objectForKey:@"key"] intValue]==@"字典值") {

[[UIApplication sharedApplication] cancelLocalNotification:myUILocalNotification];

}

}

通知执行完调用的方法 AppDelegate.m类里面

//推送完 执行的事件

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{

//notification是发送通知时传入的字典信息

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"标题" message:notification.alertBody delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];

[alert show];

[alert release];

}

最后还有一个地方:执行通知一定要退出应用才能收到通知。

IOS本地通知的更多相关文章

  1. IOS 本地通知 UILocalNotification

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

  2. iOS 本地通知 操作

    iOS 本地通知 操作 1:配置通知:然后退出程序: UILocalNotification *localNotif = [[UILocalNotification alloc] init]; loc ...

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

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

  4. xamarin.ios 本地通知推送

    由于ios10版本以后UILocalNotification被标为弃用了,所以要添加新的本地通知推送功能,下面提供一些代码参考. 一.先在AppDelegate.cs上注册本地通知推送功能. publ ...

  5. iOS: 本地通知的前后变化(iOS10)

    一.介绍  通知和推送是应用程序中很重要的组成部分.本地通知可以为应用程序注册一些定时任务,例如闹钟.定时提醒等.远程推送则更强大,提供了一种通过服务端主动推送消息到客户端的方式,服务端可以更加灵活地 ...

  6. IOS 本地通知推送消息

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

  7. IOS 本地通知

    操作流程 1.接收通知 2.注册发送通知 用途:提示时间,闹钟 //接收本地通知(在Appdelegate里面实现) - (void)application:(UIApplication *)appl ...

  8. iOS(本地通知与远程通知)

    iOS 推送通知有两种:本地推送.远程推送. 本地推送 :  在不需要联网的情况下,由APP发出推送,常用于某一时刻的通知,如闹钟.本地通送有局限性在于当APP处于后台或者退出时就无法发出通知. 远程 ...

  9. IOS 本地通知UILocalNotification

    //发送通知    UILocalNotification *notification=[[UILocalNotification alloc] init];       if (notificati ...

随机推荐

  1. Fallout4 Creation Kit

    按住SHIFT是旋转视角,按住鼠标中键 E是移动物品 双击W是旋转物品 数字键2 是调整物品大小

  2. SSIS 包单元测试检查列表

    1. 使用脚本任务(Script tasks) 组建的时候,在日志里增加一些调试信息,例如变量更新信息,可以帮助我们从日志中查看到变量是在何时何地更新的. 2. 使用ForceExecutionRes ...

  3. phpcms调用一级栏目和二级栏目

    {loop subcat(,,,$siteid) $r}  {php $num++} <strong><a href=} <br /> {elseif $n!=$c} | ...

  4. hdu 4734 数位dp

    给一个数A (十进制表示形式为AnAn-1An-2 ... A2A1,定义函数 F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1,给一个B, ...

  5. Error:“应用程序无法正常启动(0xc000007b)。请单击“确定”关闭应用程序。”

    我的电脑是 win7 64bit,用 VS2012 跑网上下载的程序,Realease | x64 模式下出现该错误. 问题出在 freeglut.dll 是 32bit 下的 dll,需要换成 64 ...

  6. [Unity3D]上海某大型游戏公司的基础面试题

    一个小老乡跟我聊到去上海某大公司的基础面试题,面试结果不尽如人意,但还是分享了下面试的试题,刚刚第一次录制视频,给某人讲课,我感觉讲的还算比较耐心,但发现一些新手入门学习的弊端,可能是很普遍的现象,这 ...

  7. 通过ajax访问Tomcat服务器web service接口时出现No 'Access-Control-Allow-Origin' header问题的解决办法

    问题描述 通过ajax访问Web服务器(Tomcat7.0.42)中的json web service接口的时候,报以下跨域问题: XMLHttpRequest cannot load http:// ...

  8. silverlight和wpf中暴露 给子类override

    protected virtual void OnSelectionChanged(SelectionChangedEventArgs args) { } public TestTabControl( ...

  9. barabasilab-networkScience学习笔记4-无标度特征

    第一次接触复杂性科学是在一本叫think complexity的书上,Allen博士很好的讲述了数据结构与复杂性科学,barabasi是一个知名的复杂性网络科学家,barabasilab则是他所主导的 ...

  10. Excel动态合并行、合并列

    背景: 在北京工作的时候,又一次同事问了我这样一个问题,说我要把从数据库获取到的数据直接通过NPOI进行导出,但是我对导出的格式要特殊的要求,如图: 冥思苦想,最终顺利帮同事解决问题,虽然有点瑕疵,但 ...