IOS 本地消息推送
2018-02-23 18:07
309 查看
1、第一步先注册推送
在AppDelegate.m编写一个推送注册方法如下:
- (void)registerLocalPush{ UILocalNotification *localNotifi = [UILocalNotification new]; [[UIApplication sharedApplication] scheduleLocalNotification:localNotifi]; /* UIUserNotificationTypeBadge = 1 << 0, // the application may badge its icon upon a notification being received UIUserNotificationTypeSound = 1 << 1, // the application may play a sound upon a notification being received UIUserNotificationTypeAlert = 1 << 2, // the application may display an alert upon a notification being */ UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings];}2、在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions函数中调用如下:- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch. [self registerLocalPush]; return YES;}3、设置推送时间
- (void)pushLocalNotifi{ // 1.创建通知 UILocalNotification *localNotification = [[UILocalNotification alloc] init]; // 2.设置通知的必选参数 // 设置通知显示的内容 localNotification.alertBody = @"推送显示的信息"; // 设置通知的发送时间,单位秒,在多少秒之后推送 localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10]; //解锁滑动时的事件 localNotification.alertAction = @"XXOOXX"; //收到通知时App icon的角标 localNotification.applicationIconBadgeNumber = 0; //推送是带的声音提醒,设置默认的字段为UILocalNotificationDefaultSoundName localNotification.soundName = UILocalNotificationDefaultSoundName; //设置推送自定义声音格式
//localNotification.soundName = @"文件名.扩展名";
//循环次数 localNotification.repeatInterval = kCFCalendarUnitDay; // 3.发送通知(根据项目需要使用) // 方式一: 根据通知的发送时间(fireDate)发送通知 [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];}
4、调用推送时间设置
- (IBAction)clickLocalPush:(id)sender{ [self pushLocalNotifi];}
在AppDelegate.m编写一个推送注册方法如下:
- (void)registerLocalPush{ UILocalNotification *localNotifi = [UILocalNotification new]; [[UIApplication sharedApplication] scheduleLocalNotification:localNotifi]; /* UIUserNotificationTypeBadge = 1 << 0, // the application may badge its icon upon a notification being received UIUserNotificationTypeSound = 1 << 1, // the application may play a sound upon a notification being received UIUserNotificationTypeAlert = 1 << 2, // the application may display an alert upon a notification being */ UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings];}2、在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions函数中调用如下:- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch. [self registerLocalPush]; return YES;}3、设置推送时间
- (void)pushLocalNotifi{ // 1.创建通知 UILocalNotification *localNotification = [[UILocalNotification alloc] init]; // 2.设置通知的必选参数 // 设置通知显示的内容 localNotification.alertBody = @"推送显示的信息"; // 设置通知的发送时间,单位秒,在多少秒之后推送 localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10]; //解锁滑动时的事件 localNotification.alertAction = @"XXOOXX"; //收到通知时App icon的角标 localNotification.applicationIconBadgeNumber = 0; //推送是带的声音提醒,设置默认的字段为UILocalNotificationDefaultSoundName localNotification.soundName = UILocalNotificationDefaultSoundName; //设置推送自定义声音格式
//localNotification.soundName = @"文件名.扩展名";
//循环次数 localNotification.repeatInterval = kCFCalendarUnitDay; // 3.发送通知(根据项目需要使用) // 方式一: 根据通知的发送时间(fireDate)发送通知 [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];}
4、调用推送时间设置
- (IBAction)clickLocalPush:(id)sender{ [self pushLocalNotifi];}
相关文章推荐
- iOS开发本地通知(每天定点发送消息推送)
- ios本地消息推送(二)
- ios 本地通知与消息推送
- iOS项目开发实战——实现苹果本地消息通知推送服务
- iOS开发消息推送机制——本地推送。
- iOS 消息推送及本地通知,原理解析
- IOS iOS本地推送---常用开发中,通过消息传递信息
- IOS开发中本地消息推送方法
- iOS的本地消息推送。
- IOS中程序如何进行推送消息(本地推送,远程推送)
- IOS开发中本地消息推送方法
- IOS开发中本地消息推送方法
- ios UIApplication 在本地消息的推送上的应用
- IOS iOS本地推送---常用开发中,通过消息传递信息
- IOS 本地推送消息以及进入后台继续推送
- IOS 本地通知推送消息
- IOS-推送消息(本地推送)
- iOS本地推送消息
- 轻松搞定iOS本地消息推送
- IOS_本地通知_消息推送_微博_蓝牙_ImagePicker