美文网首页
本地通知

本地通知

作者: 小小东 | 来源:发表于2015-09-06 14:58 被阅读133次

网站:(协议方法暂时没走,可以推送)

http://www.111cn.net/sj/iOS/60372.htm

下面的网站比较详细(协议方法没测试)

http://m.blog.csdn.net/blog/u011872945/11779133

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

if (localNotification == nil) {

return;

}

//设置本地通知的触发时间(如果要立即触发,无需设置),这里设置为20妙后

localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];

//设置本地通知的时区

localNotification.timeZone = [NSTimeZone defaultTimeZone];

// 设置应用程序右上角的提醒个数

localNotification.applicationIconBadgeNumber++;

//设置通知的内容

localNotification.alertBody = @"我来提示你一下下";

//设置通知动作按钮的标题

localNotification.alertAction = @"查看";

//设置提醒的声音,可以自己添加声音文件,这里设置为默认提示声

localNotification.soundName = UILocalNotificationDefaultSoundName;

//设置通知的相关信息,这个很重要,可以添加一些标记性内容,方便以后区分和获取通知的信息

NSDictionary *infoDic = [NSDictionary dictionaryWithObjectsAndKeys:@"affair.schedule",@"id",[NSNumber numberWithInteger:5],@"time",[NSNumber numberWithInt:10],@"affair.aid", nil];

localNotification.userInfo = infoDic;

//在规定的日期触发通知

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

APP上的小红色数字需要用户查看通知,或者通知结束的去掉,需要下面两个方法

程序没运行

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

application.applicationIconBadgeNumber=0;

UILocalNotification *uinfo=[launchOptions objectForKey:@"UIApplicationLaunchOptionsLocalNotificationKey"];

if(uinfo!=nil){

NSDictionary *dic=uinfo.userInfo//就使本地通知中传递过的NSDictionary,我们可以获取其中的参数。

}

}

程序运行

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

NSDictionary *userInfo=notification.userInfo;

NSString *sfiredateformat=[NSMutableString stringWithString:[userInfo objectForKey:@"firedateformat"]];

NSDateFormatter *formatter=[[[NSDateFormatter alloc] init] autorelease];

[formatter setDateFormat:sfiredateformat];

if([[formatter dateFromString:[formatter stringFromDate:[NSDate date]]] timeIntervalSinceDate:notification.fireDate]>0.5){

//用户点击了,

}else{

//时间到了触发的

}

}

里面介绍了如果APP在运行闹钟不会响起来,通过音乐播放器来使其响起来了,但音乐好像是需要设置一个固定的(代码中固定,手机不可自己更改的)

网站:

http://www.codes51.com/article/detail_162240.html

相关文章

  • iOS 通知的使用

    源地址 本地通知属于UIKit框架、推送通知属于Foundation框架。 本地通知 本地通知是由本地应用触发的,...

  • iOS10 通知框架总结

    通知分为本地通知和远端通知,这里着重介绍本地通知。本地通知有三个步骤 Appdelegate中申请通知权限 App...

  • 通知--本地通知

    本地通知是由本地应用触发的,它是基于时间行为的一种通知形式,例如闹钟定时、待办事项提醒,又或者一个应用在一段时候后...

  • iOS 本地推送通知

    本地推送通知 对本地通知的数量限制,iOS最多允许最近本地通知数量是64个,超过限制的本地通知将被iOS忽略。 a...

  • 本地推送通知、远程推送通知、激光推送

    title : 本地推送通知、远程推送通知、激光推送category : UI 本地推送通知、远程推送通知、激光...

  • UILocalNotification

    本文内容a.注册普通本地通知b.自定义操作的本地通知c.自定义可快捷回复的本地通知 注册普通本地通知 创建一个本地...

  • iOS14开发- 通知

    iOS 中的通知主要分为 2 种,本地通知和远程通知。 本地通知 使用步骤 导入UserNotifications...

  • iOS开发- 推送服务

    1,注册本地通知 使用本地通知之前是需要预先设置好通知的一些基本属性,然后向系统注册本地通知,通知会在设定好的时间...

  • 本地推送/本地通知

    一、本地推送/本地通知 是什么? (名称概念)本地推送,其实也就是本地通知,它们指的是同一种概念,只是叫法不同,下...

  • 本地通知

    iOS系统可支持本地通知和远程通知,一个通知在客户端收到的时候可能是一个通知窗体,可能会播放一段通知声音,还有可能...

网友评论

      本文标题:本地通知

      本文链接:https://www.haomeiwen.com/subject/imtlcttx.html