您的位置:首页 > 其它

推送

2016-03-28 20:34 225 查看
今天我给大家讲讲,关于本地推送通知的使用

1、远程推送(Remote Notification)

2、本地推送 (Local Notification)

推送通知就是该app无论是在使用中,还是没有没有使用,都可以通过这个通知告诉使用者,它喜欢的app的相关消息。

注意:发送推送通知的时候,如果APP在前台运行,那么推送的通知不会被呈现出来

推送都能如期发出,但是用户 不一定能如期去接收。
UIUserNotificationSettings推送通知的类

通知的几种格式,可以同时一起放在字典中
UIUserNotificationTypeNone = 0, 没有样式

UIUserNotificationTypeBadge = 1 << 0,右上角

UIUserNotificationTypeSound = 1 << 1,有声音

UIUserNotificationTypeAlert = 1 << 2,弹出

首先我们都先在AppDelegate中写
1、查询该设备的版本(返回的是double类型):
[UIDevice currentDevice].systemVersion.doubleValue

UIUserNotificationSettings *set = [UIUserNotificationSettings
settingsForTypes:
UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert
categories:nil];
[application
registerUserNotificationSettings:set];

if
(launchOptions[UIApplicationLaunchOptionsLocalNotificationKey]) {

UILabel
*label =[[UILabel
alloc]init];

label.frame
=CGRectMake(0,
300,
300,
300);

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

label.font
=[UIFont
systemFontOfSize:14];

label.numberOfLines
=0;

[self.window.rootViewController.view
addSubview:label];

}
//接到通知走这

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

UILabel
*label =[[UILabel

alloc]init];

label.frame
=CGRectMake(0,

300,

300,

300);

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

label.font
=[UIFont

systemFontOfSize:14];

label.numberOfLines
=
0;

label.backgroundColor
= [UIColor

blackColor];

[self.window.rootViewController.view

addSubview:label];

}
在viewController中写

UILocalNotification
*loc = [UILocalNotification
new];

loc.fireDate
= [NSDate
dateWithTimeIntervalSinceNow:3];

//
具体内容

loc.alertBody
=
@"dddddd";

//
允许运行

loc.hasAction
=
YES;

//
弹出框的名字

loc.alertAction
=
@"ssssss";

//
角标的显示

loc.applicationIconBadgeNumber
=
5;

//
给声音

loc.soundName
=
UILocalNotificationDefaultSoundName;

[[UIApplication

sharedApplication]

scheduleLocalNotification:loc];
[[UIApplication
sharedApplication] setApplicationIconBadgeNumber:0];

移除通知

[[UIApplication
sharedApplication]cancelAllLocalNotifications];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: