UILocalNotification本地推送
来源:互联网 发布:sopcast网络电视安卓版 编辑:程序博客网 时间:2024/06/06 23:59
//远程推送 –> 服务器(第三方 umeng JPush(极光)) –> APNS
本地推送
Demo1
//获取推送权限
UIUserNotificationType type = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
NSDate *fireDate = [NSDate dateWithTimeIntervalSinceNow:10];NSLog(@"fireDate=%@",fireDate);localNotification.fireDate = fireDate;// 时区localNotification.timeZone = [NSTimeZone defaultTimeZone];// 设置重复的间隔localNotification.repeatInterval = kCFCalendarUnitSecond;// 通知内容localNotification.alertBody = @"该起床了...";localNotification.applicationIconBadgeNumber = 1;// 通知被触发时播放的声音localNotification.soundName = UILocalNotificationDefaultSoundName;// 通知参数NSDictionary *userDict = [NSDictionary dictionaryWithObject:@“哈哈哈” forKey:@"key"];localNotification.userInfo = userDict;// ios8后,需要添加这个注册,才能得到授权if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) { UIUserNotificationType type = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound; UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings];} // 执行通知注册[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
(void)application:(UIApplication )application didReceiveLocalNotification:(UILocalNotification )notification {
NSLog(@”noti:%@”,notification);// 这里真实需要处理交互的地方
// 获取通知所带的数据
NSString *notMess = [notification.userInfo objectForKey:@”key”];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”本地通知(前台)”message:notMess
delegate:nil
cancelButtonTitle:@”OK”
otherButtonTitles:nil];
[alert show];// 更新显示的徽章个数
NSInteger badge = [UIApplication sharedApplication].applicationIconBadgeNumber;
badge–;
badge = badge >= 0 ? badge : 0;
[UIApplication sharedApplication].applicationIconBadgeNumber = badge;// 在不需要再推送时,可以取消推送
//[HomeViewController cancelLocalNotificationWithKey:@”key”];
}
Demo2
//本地推送
//远程推送 –> 服务器(第三方 umeng JPush(极光)) –> APNS
@interface ViewController ()
@end
@implementation ViewController
-(void)localNotification
{
UILocalNotification *local = [[UILocalNotification alloc] init];
//发送的时间local.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];//时区local.timeZone = [NSTimeZone defaultTimeZone];//设置发送的消息local.alertBody = @"哈哈哈";//设置应用程序的徽标local.applicationIconBadgeNumber = 1;//设置声音local.soundName = UILocalNotificationDefaultSoundName;//userInfolocal.userInfo = @{@"key":@"阿斯顿和父爱和发件客户卡拉好看哈克龙"};//获取推送的权限if([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]){ UIUserNotificationType type = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound; UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings];}[[UIApplication sharedApplication] scheduleLocalNotification:local];//取消本地推送//[UIApplication sharedApplication] cancelLocalNotification:(nonnull UILocalNotification *)
}
- 本地推送 UILocalNotification
- 本地推送 UILocalNotification
- 本地推送UILocalNotification
- 本地推送UILocalNotification
- 本地推送 UILocalNotification
- 本地推送UILocalNotification
- UILocalNotification本地推送机制
- 本地推送UILocalNotification
- 本地推送UILocalNotification
- iOS 本地推送 UILocalNotification
- UILocalNotification本地推送
- 本地推送UILocalNotification(整理)
- 本地推送UILocalNotification
- 本地推送通知UILocalNotification
- iOS 本地推送 UILocalNotification
- 本地推送UILocalNOtification整理
- 本地推送 UILocalNotification
- UILocalNotification本地推送
- Android最佳的开源库集锦
- 菜鸟笔记之基础语法
- [C++]1.指针的学习
- JFinal Web开发学习(九)首页layui重新构建目录以及首页
- 欢迎使用CSDN-markdown编辑器
- UILocalNotification本地推送
- OpenStack开发源码如何获取及下载
- 猪肉都被绑上了“家族标签”,大数据已波及到农牧业!
- 修改创建jsp模板改为Html5
- 全键输入提示
- MAC MYSQL修改root密码
- SQL那些事儿(十一)--ODBC,OLE-DB,ADO.NET区别
- MySQL之浅谈MySQL的存储引擎
- ceph pg和pgp的区别