ios开发中本地消息推送方法

ios开发中本地消息推送方法

ID:16237018

大小:32.50 KB

页数:5页

时间:2018-08-08

ios开发中本地消息推送方法_第1页
ios开发中本地消息推送方法_第2页
ios开发中本地消息推送方法_第3页
ios开发中本地消息推送方法_第4页
ios开发中本地消息推送方法_第5页
资源描述:

《ios开发中本地消息推送方法》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、第一步:接收本地推送实现代理方法didReceiveLocalNotification-(void)application:(UIApplication*)applicationdidReceiveLocalNotification:(UILocalNotification*)notification{//在此时设置解析notification,并展示提示视图}第二步:创建本地推送-(void)createLocalNotification{//创建一个本地推送UILocalNotification*notification=[[[UILocalNotifi

2、cationalloc]init]autorelease];//设置10秒之后NSDate*pushDate=[NSDatedateWithTimeIntervalSinceNow:10];if(notification!=nil){//设置推送时间notification.fireDate=pushDate;//设置时区notification.timeZone=[NSTimeZonedefaultTimeZone];//设置重复间隔notification.repeatInterval=kCFCalendarUnitDay;//推送声音notificat

3、ion.soundName=UILocalNotificationDefaultSoundName;//推送内容notification.alertBody=@"推送内容";//显示在icon上的红色圈中的数子notification.applicationIconBadgeNumber=1;//设置userinfo方便在之后需要撤销的时候使用NSDictionary*info=[NSDictionarydictionaryWithObject:@"name"forKey:@"key"];notification.userInfo=info;//添加推送到U

4、IApplicationUIApplication*app=[UIApplicationsharedApplication];[appscheduleLocalNotification:notification];}}第三步:解除本地推送-(void)removeLocalNotication{//获得UIApplicationUIApplication*app=[UIApplicationsharedApplication];//获取本地推送数组NSArray*localArray=[appscheduledLocalNotifications];//声明

5、本地通知对象UILocalNotification*localNotification;if(localArray){for(UILocalNotification*notiinlocalArray){NSDictionary*dict=noti.userInfo;if(dict){NSString*inKey=[dictobjectForKey:@"key"];if([inKeyisEqualToString:@"对应的key值"]){if(localNotification){[localNotificationrelease];localNotific

6、ation=nil;}localNotification=[notiretain];break;}}}//判断是否找到已经存在的相同key的推送if(!localNotification){//不存在初始化localNotification=[[UILocalNotificationalloc]init];}if(localNotification){//不推送取消推送[appcancelLocalNotification:localNotification];[localNotificationrelease];return;}}}

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。