美文网首页
消息推送(本地推送)

消息推送(本地推送)

作者: 帥陽 | 来源:发表于2017-02-08 15:44 被阅读18次

zone 时区 badge 图标

//iOS8之后需要注册通知类型包含哪些(声音,图标文字,文本)信息

/*

UIUserNotificationTypeNone    = 0,

UIUserNotificationTypeBadge   = 1 << 0,包含图标文字0001

UIUserNotificationTypeSound   = 1 << 1, //声音0010

UIUserNotificationTypeAlert   = 1 << 2, //主题内容0100

*/

//0111

UIUserNotificationSettings*setting = [UIUserNotificationSettingssettingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlertcategories:nil];

[[UIApplicationsharedApplication]registerUserNotificationSettings:setting];

//1.创建一个本地通知

UILocalNotification*local= [[UILocalNotificationalloc]init];

// timer-based scheduling定制特定的时间发出通知

@property(nonatomic,copy) NSDate *fireDate;触发时间

@property(nonatomic,copy) NSTimeZone *timeZone;时区

@property(nonatomic) NSCalendarUnit repeatInterval;重复间隔// 0 means don't repeat

@property(nonatomic,copy) NSCalendar *repeatCalendar;重复间隔

@property(nonatomic,copy) CLRegion *regionNS_AVAILABLE_IOS(8_0);//区域

@property(nonatomic,assign)BOOLregionTriggersOnceNS_AVAILABLE_IOS(8_0);//决定区域的一个bool值

// alerts

@property(nonatomic,copy) NSString *alertBody;提醒的主题

@property(nonatomic)BOOLhasAction;// NO不显示滑动解锁的按钮反之显示

@property(nonatomic,copy) NSString *alertAction;//滑动解锁的文字

@property(nonatomic,copy) NSString *alertLaunchImage;//点击通知横幅的启动程序的启动图片

@property(nonatomic,copy) NSString *alertTitle提示的标题文字

// sound默认: UILocalNotificationDefaultSoundName

@property(nonatomic,copy) NSString *soundName;

// badge

@property(nonatomic) NSInteger applicationIconBadgeNumber;//图标文字

// user info

@property(nonatomic,copy) NSDictionary *userInfo;//用户指定的携带参数

[UIUserNotificationSettings settingsForUserNotificationTypes:userNotificationActionSettings:]

@property(nonatomic, copy) NSString *categoryNS_AVAILABLE_IOS(8_0);分类

//设置属性

local.alertBody=@"女神:在吗?";

local.fireDate= [NSDatedateWithTimeIntervalSinceNow:5];

local.soundName=UILocalNotificationDefaultSoundName;

local.alertAction=@"约";

local.applicationIconBadgeNumber=8;

local.userInfo=@{@"name":@"女神",@"content":@"在吗?",@"time":@"20180815"};

//应用级别

//定制一个通知用代理监听什么接收到通知

[[UIApplicationsharedApplication]scheduleLocalNotification:local];

//立即发出通知

[[UIApplicationsharedApplication]presentLocalNotificationNow:local];

//取消所有的本地通知

[[UIApplicationsharedApplication]cancelAllLocalNotifications];

/**

*接收到本地通知的时候就会调用

*程序在前台:会调用程序在后台:点击横幅就算接收通知也会调用->程序活着就会调用

*@paramapplication应用

*@paramnotification通知

*/

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

{

//调试:

//1>控制台

NSLog(@"%@",notification);

//2>添加控件

UILabel*label = [[UILabelalloc]initWithFrame:CGRectMake(0,0,320,300)];

label.backgroundColor= [UIColorredColor];

label.text= [NSStringstringWithFormat:@"%@",notification];

[self.window.rootViewController.viewaddSubview:label];

//跳转对应的界面

}

/**

*程序从死到生程序启动:1>点击图标启动2>接收通知(点击横幅)

*

*@paramapplication   <#application description#>

*@paramlaunchOptions <#launchOptions description#>

*

*@return<#return value description#>

*/

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

//UIApplicationLaunchOptionsLocalNotificationKey接收到本地通知才会来到这里

UILocalNotification*info = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];

if(info) {

UILabel*label = [[UILabelalloc]initWithFrame:CGRectMake(0,0,320,300)];

label.backgroundColor= [UIColororangeColor];

[self.window.rootViewController.viewaddSubview:label];

//取出携带信息

label.numberOfLines=0;

//NSDictionary *dict = info[@"UIConcreteLocalNotification"];

// NSArray *keys = [info allKeys];

//for (NSString *str in keys) {

//   label.text = [NSString stringWithFormat:@"%@",str];

//}

//NSDictionary *dict1 = dict[@"user info"];

label.text= [NSStringstringWithFormat:@"%@",info.userInfo];

//跳转对应的界面

}

returnYES;

}

相关文章

  • 消息推送(本地推送)

    zone 时区 badge 图标 //iOS8之后需要注册通知类型包含哪些(声音,图标文字,文本)信息 /* UI...

  • iOS - 10以后的本地通知

    参考文章OS 10 消息推送(UserNotifications)秘籍总结 1,本地推送 1,注册本地推送2,本地...

  • 消息推送(本地、远程推送)

    本地推送 概述: 本地推送主要运用在系统工具中,如闹钟、生日提醒等。 具体步骤: 1:实例化一个推送对象2:为推送...

  • 本地消息推送

    注册本地通知 - (BOOL)application:(UIApplication *)application d...

  • iOS 消息推送--本地推送-网络推送

    本地推送 "AppDelegate.m" ViewController.m 远程推送 AppDelegate.m ...

  • 本地推送以及远程推送

    1、什么是本地推送?所谓的本地推送就是app自己给系统推送的一些消息就叫做本地推送。2、本地推送的基本应用:有设置...

  • iOS本地通知和远程推送

    iOS 本地通知和远程推送 推送通知的应用,可以推送最新的消息给用户,获得更多的关注。推送分为本地推送和远程推送两...

  • iOS 接入个推消息推送

    前言 消息推送包含本地推送(Local Notification)和远程推送(Remote Notificatio...

  • 本地推送UILocalNotification

    1、增加一个本地推送 2、程序运行时接收到本地推送消息 3、取消一个本地推送

  • iOS-消息推送

    iOS 消息推送包括远程推送通知(Remote Notification)和本地推送通知(Local Notifi...

网友评论

      本文标题:消息推送(本地推送)

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