本地推送,远程推送(JPUSHService极光推送例)
2016-02-29 14:36
218 查看
本地推送,例:app闹钟,定时提醒==
/*
//iOS8以后需要先注册本地通知,需要经过用户的同意
if ([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0) {
UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:setting];
}
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
//触发的时间
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
//通知的内容
localNotification.alertBody = @"时间到了,该起床了";
//启动通知
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
//设置应用程序显示的徽标
[UIApplication sharedApplication].applicationIconBadgeNumber = 99;
*/
远程推送
例:
#import "AppDelegate.h"
#import "JPUSHService.h"
static NSString *appKey =
@"18a57d31ebab4f9be6932d61";
static NSString *channel =
@"Publish channel";
static
BOOL isProduction =
FALSE;
@interface
AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
//注册远程推送
if ([[UIDevice
currentDevice].systemVersion
floatValue] >= 8.0) {
//可以添加自定义categories
[JPUSHService
registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
}
else {
//categories
必须为nil
[JPUSHService
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
[JPUSHService
setupWithOption:launchOptions
appKey:appKey
channel:channel
apsForProduction:isProduction];
return
YES;
}
//将令牌传送给极光推送服务器
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[JPUSHService
registerDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary
*)userInfo{
[JPUSHService
handleRemoteNotification:userInfo];
NSLog(@"收到通知");
}
//已经接收到远程推送
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary
*)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[JPUSHService
handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
/*
//iOS8以后需要先注册本地通知,需要经过用户的同意
if ([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0) {
UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:setting];
}
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
//触发的时间
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
//通知的内容
localNotification.alertBody = @"时间到了,该起床了";
//启动通知
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
//设置应用程序显示的徽标
[UIApplication sharedApplication].applicationIconBadgeNumber = 99;
*/
远程推送
例:
#import "AppDelegate.h"
#import "JPUSHService.h"
static NSString *appKey =
@"18a57d31ebab4f9be6932d61";
static NSString *channel =
@"Publish channel";
static
BOOL isProduction =
FALSE;
@interface
AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
//注册远程推送
if ([[UIDevice
currentDevice].systemVersion
floatValue] >= 8.0) {
//可以添加自定义categories
[JPUSHService
registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
}
else {
//categories
必须为nil
[JPUSHService
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
[JPUSHService
setupWithOption:launchOptions
appKey:appKey
channel:channel
apsForProduction:isProduction];
return
YES;
}
//将令牌传送给极光推送服务器
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[JPUSHService
registerDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary
*)userInfo{
[JPUSHService
handleRemoteNotification:userInfo];
NSLog(@"收到通知");
}
//已经接收到远程推送
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary
*)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[JPUSHService
handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
相关文章推荐
- java模拟浏览器上传文件
- Android常见控件— — —EditText
- 浅谈web网站架构演变过程
- Android Binder 透传 Fd流程
- 如何在eclipse中看到java基础类的源代码
- Cornerstone “An error occurred and the operation could not be completed”
- Erlang 连接mongoDB
- ImageLoader----内存缓存
- opencv移动目标检测一
- Windows Server 2012 R2:细节信息汇总
- 红黑树和二叉平衡树详细介绍
- Ask Hoegh(5)——buffer cache和buffer有什么区别?
- SpringMVC中使用Interceptor拦截器
- C/C++中产生随机数(rand,srand用法)
- 2016年最新的搜索引擎,排名优化原理分析
- 容器操作4 容器的大小
- 微信支付 商户API密钥key的生成与设置
- 提高代码质量:如何编写函数
- Shell特殊变量
- C++ DirectX 游戏开发初级视频教程 21 资源下载链接