美文网首页00『 基础知识 』iOS 开发 iOS Developer
极光推送之应用内外消息推送 核心代码

极光推送之应用内外消息推送 核心代码

作者: XLsn0w | 来源:发表于2016-08-31 09:25 被阅读160次

#pragma mark -极光推送

#define kNotificationTypes (UIUserNotificationTypeBadge | UIUserNotificationTypeSound |UIUserNotificationTypeAlert)

- (void)initJPushWithOptions:(NSDictionary*)launchOptions {

if([[UIDevicecurrentDevice].systemVersionfloatValue] >=8.0) {

[JPUSHServiceregisterForRemoteNotificationTypes:kNotificationTypes

categories:nil];//可以添加自定义categories

}else{

[JPUSHServiceregisterForRemoteNotificationTypes:kNotificationTypes

categories:nil];//categories必须为nil

}

//启动SDK

[JPUSHServicesetupWithOption:launchOptionsappKey:kJPushAppKey

channel:@"App Store"

apsForProduction:NO

advertisingIdentifier:nil];

}

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {

[JPUSHServiceregisterDeviceToken:deviceToken];//注册DeviceToken

}

#pragma mark -应用外接收推送信息JPush

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo {

NSDictionary*aps = [userInfovalueForKey:@"aps"];//取得APNs标准信息内容

NSString*alert = [apsvalueForKey:@"alert"];//推送显示的内容key为alert

NSIntegerbadge = [[apsvalueForKey:@"badge"]integerValue];//badge数量

//NSString *sound = [aps valueForKey:@"sound"]; //播放的声音

UIAlertController*alertController = [UIAlertControlleralertControllerWithTitle:@"通知"message:alertpreferredStyle:UIAlertControllerStyleAlert];

UIAlertAction*okAlertAction = [UIAlertActionactionWithTitle:@"知道了"style:UIAlertActionStyleDefaulthandler:nil];

[alertControlleraddAction:okAlertAction];

[self.window.rootViewControllerpresentViewController:alertControlleranimated:YEScompletion:nil];

[UIApplicationsharedApplication].applicationIconBadgeNumber= badge;

// Required

[JPUSHServicehandleRemoteNotification:userInfo];

}

#pragma mark -添加JPush应用内接收自定义消息

- (void)addJPushCustomMessage {

[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(networkDidReceiveMessage:)name:kJPFNetworkDidReceiveMessageNotificationobject:nil];

}

- (void)networkDidReceiveMessage:(NSNotification*)notification {

NSDictionary*userInfo = [notificationuserInfo];

NSString*content = [userInfovalueForKey:@"content"];//推送显示的内容key为content

UIAlertController*alertController = [UIAlertControlleralertControllerWithTitle:@"通知"message:contentpreferredStyle:UIAlertControllerStyleAlert];

UIAlertAction*okAlertAction = [UIAlertActionactionWithTitle:@"知道了"style:UIAlertActionStyleDefaulthandler:nil];

[alertControlleraddAction:okAlertAction];

[self.window.rootViewControllerpresentViewController:alertControlleranimated:YEScompletion:nil];

}

相关文章

  • 极光推送之应用内外消息推送 核心代码

    #pragma mark -极光推送#define kNotificationTypes (UIUserNotif...

  • 极光推送进行远程推送

    借阅:极光推送进行远程推送 怎么使用极光推送进行远程推送 在极光官网注册极光推送创建一个应用在应用配置中导入两个证...

  • iOS极光推送开发入门

    一、什么叫极光推送 极光推送(JPush)是独立的第三方云推送平台,致力于为全球移动应用开发者提供移动消息推送服务...

  • JPush推送(极光推送)推送消息

    jpush推送 其正常工作的必要条件是:JPush SDK 与 JPush Server 的网络保持着连接。请参考...

  • 在 android Notification使用PendingI

    项目的推送是采用极光推送,使用的是极光推送自定义消息,自己弹出通知栏,当有多天消息推送的时候PendingI...

  • 极光推送集成开发

    1.极光推送集成与设置 极光推送地址①注册极光推送账号。②在应用管理内按照步骤创建APP。③找到“文档——iOS—...

  • 记一次极光推送的集成需求

    应用场景 1.app在前台状态时,在app内推送2.app在后台状态时,在消息栏推送 集成Jpush 极光推送集成...

  • iOS 极光推送

    证书的制作就不说了,下面看看怎么使用极光推送进行远程推送 一、配置 在极光官网注册极光推送2.创建一个应用在应用配...

  • 极光推送第一篇:配置

    极光推送第二篇:消息处理极光推送第三篇:消息跳转和自定义 相信很多人都是用的极光推送,因为名字好看。官方也有文档:...

  • 极光推送第三篇:消息跳转和自定义

    极光推送第一篇:配置极光推送第二篇:消息处理 上一篇极光推送第二篇:消息接收中我们接收并打印了消息,这一篇我们看看...

网友评论

    本文标题:极光推送之应用内外消息推送 核心代码

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