使用极光推送 ios 收不到ios客户端应该在怎么设置标签

iOS SDK 教程
iOS SDK 调试指南
iOS 调试思维导图
请到“应用详情页面”确认证书可用性:
开发环境测试
在对 JPush iOS 开发环境进行测试前,请确保 3 个统一:
App 是开发环境打包(开发证书 Development)上传了开发证书并验证通过Portal 上的应用设置为开发环境
发布环境测试
在对 JPush iOS 生产环境进行测试前,请确保 3 个统一:
App 是 ad-hoc 打包或者App Store 版本(发布证书 Production)上传了发布证书并验证通过Portal 上的应用设置为生产环境
可能存在的其他问题
收到消息不够稳定
JPush iOS 是对原生官方 APNs 推送的一个补充,是对其的封装,以帮助开发人员更轻松地使用 APNs 。
由于APNs 本身不承诺保证消息到达,客户端网络与服务器端的连通性,对 APNs 是否及时接收到消息具有很大的影响。
iOS 证书 设置指南
创建应用程序ID
登陆&&选择进入iOS Provisioning Portal。
在&中,点击App IDs进入App ID列表。
创建 App ID,如果 ID 已经存在可以直接跳过此步骤
为 App 开启 Push Notification 功能。如果是已经创建的 App ID 也可以通过设置开启 Push Notification 功能。
根据实际情况完善 App ID 信息并提交,注意此处需要指定具体的 Bundle ID 不要使用通配符。
配置和下载证书
如果你之前没有创建过 Push 证书或者是要重新创建一个新的,请在证书列表下面新建。
新建证书需要注意选择证书种类(开发证书用于开发和调试使用,生产证书用于 App Store 发布)
点击 Continue 后选择证书对应的应用ID,然后继续会出现“About Creating a Certificate Signing Request (CSR)”。
根据它的说明创建打开KeychainAccess 创建 Certificate Signing Request。
填写“User Email Address”和“Common Name” 后选择 Saved to disk 进行保存 。
继续返回Apple developer 网站点击 Continue ,上传刚刚生成的 .certSigningRequest 文件生成 APNs Push Certificate。下载并双击打开证书,证书打开时会启动“钥匙串访问”工具。在“钥匙串访问”中你的证书会显示在“我的证书”中,注意选择“My Certificates” 和&login&
导出 .p12 证书文件
注意要选“login”和“My Certificates” 导出证书时要选中证书文件,不要展开private key。
将文件保存为Personal Information Exchange (.p12)格式。
将文件保存为Personal Information Exchange (.p12)格式。
在&,针对某应用程序,上传上面步骤得到 .p12 证书文件。这是 iOS SDK 能够接收到 JPush 推送消息的必要步骤。
Provisioning Profile的创建
假设创建了一个App ID:cn.jpush.examlpe,并为此App ID配置开发环境的Push Notifications:
创建该App ID的推送证书,如下图:
创建App ID、APN证书和p12证书的导出的具体步骤请看 :
点击下图按钮开始创建Provisioning Profile:
选择此Provisioning Profile的环境后点击[Continue]:
选择要创建Provisioning Profile的App ID后点击[Continue]:
选择所属的开发者证书,(这里创建了多个开发者证书,建议只创建一个,方便管理)为了方便,选择了[Select All],再点击[Continue]进入下一步:
为该Provisioning Profile选择将要安装的设备(一般选择[Select All]),点击[Continue]:
给该Provisioning Profile填写Profile Name,点击[generate]完成创建。
点击[DownLoad]下载Provisioning Profile:
双击下载下来的Provisioning Profile,添加到xcode。
XCode的证书配置教程
参照集成JPush SDK 和上传了推送用到的p12证书后在编译运行前需要先配置一下证书,步骤如下:
打开xxx-info.plist的Bundle identifier项把上传到JPush 控制台的bundle id填写进去:
点击项目,进入Build Setting 界面,向下滑动,去到Code Signing 配置证书:
iOS 7 Background Remote Notification
本次iOS 7在推送方面最大的变化就是允许,应用收到通知后在后台(background)状态下运行一段代码,可用于从服务器获取内容更新。功能使用场景:(多媒体)聊天,Email更新,基于通知的订阅内容同步等功能,提升了终端用户的体验。
Remote Notifications 与之前版本的对比可以参考下面两张 Apple 官方的图片便可一目了然。
如果只携带content-available: 1 不携带任何badge,sound 和消息内容等参数,则可以不打扰用户的情况下进行内容更新等操作即为“Silent Remote Notifications”。
客户端设置
开启Remote notifications
需要在Xcode 中修改应用的 Capabilities 开启Remote notifications,请参考下图:
修改通知处理函数
当注册了Backgroud Modes -& Remote notifications 后,notification 处理函数一律切换到下面函数,后台推送代码也在此函数中调用。
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler;
服务端推送设置
推送消息携带 content-available: 1 是Background 运行的必须参数,如果不携带此字段则与iOS7 之前版本的普通推送一样。
使用Web Portal 推送
在“可选设置内”选择对应的参数。
使用 API 推送
只需在&的 ios 内附加content-available&:true 字段即可
限制与注意
“Silent Remote Notifications”是在 Apple 的限制下有一定的频率控制,但具体频率不详。所以并不是所有的 “Silent Remote Notifications” 都能按照预期到达客户端触发函数。“Background”下提供给应用的运行时间窗是有限制的,如果需要下载较大的文件请参考 Apple 的 NSURLSession 的介绍。“Background Remote Notification” 的前提是要求客户端处于Background 或 Suspended 状态,如果用户通过 App Switcher 将应用从后台 Kill 掉应用将不会唤醒应用处理 background 代码。
更详细的说明资料请查阅 Apple 官方的 iOS 开发文档。
iOS 8 UIUserNotificationSettings
v1.8.0 版本开始。
本次iOS 8在推送方面最大的变化就是修改了推送的注册接口,在原本的推送type的基础上,增加了一个categories参数,这个参数的目的是用来注册一组和通知关联起来的button的事件。这个categories由一系列的 UIUserNotificationCategory组成。每个UIUserNotificationCategory对象包含你的app用来响应本地或者远程通知的信息。每一个对象的title作为通知上每一个button的title展示给用户。当用户点击了某一个button,系统将会调用应用内的回调函数或者。
客户端设置
使用UIUserNotificationCategory
if ([[UIDevice currentDevice].systemVersion floatValue] &= 8.0) {
NSMutableSet *categories = [NSMutableSet set];
UIMutableUserNotificationCategory *category = [[UIMutableUserNotificationCategory alloc] init];
category.identifier = @&identifier&;
UIMutableUserNotificationAction *action = [[UIMutableUserNotificationAction alloc] init];
action.identifier = @&test2&;
action.title = @&test&;
action.activationMode = UIUserNotificationActivationModeB
action.authenticationRequired = YES;
//YES显示为红色,NO显示为蓝色
action.destructive = NO;
NSArray *actions = @[ action ];
[category setActions:actions forContext:UIUserNotificationActionContextMinimal];
[categories addObject:category];
使用UIUserNotificationType
if ([[UIDevice currentDevice].systemVersion floatValue] &= 8.0) {
[APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)
categories:categories];
[APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)
categories:nil];
使用回调函数
// Called when your app has been activated by the user selecting an action from
// a remote notification.
// A nil action identifier indicates the default action.
// You should call the completion handler as soon as you've finished handling
// the action.
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo
completionHandler:(void (^)())completionHandler {
服务端设置
服务端payload格式:aps增加category字段,当该字段与客户端UIMutableUserNotificationCategory的identifier匹配时,触发设定的action和button显示。
payload example:
{&aps&:{&alert&:&example&, &sound&:&default&, &badge&: 1, &category&:&identifier&}}
iOS 9 UIUserNotificationActionBehaviorTextInput
v1.8.0 版本开始
本次iOS 9在推送方面最大的变化就是修改了推送Category的类型,在原本的推送categories的基础上,增加了一个text Action类型,这个参数的目的是用来注册通过通知快捷文字输入的事项。这个categories由一系列的 UIUserNotificationCategory组成。每个UIUserNotificationCategory对象允许添加一组UIMutableUserNotificationAction类型的参数来增加通知栏上的项目。如今iOS9在原有的UIMutableUserNotificationAction类型增加了Text输入类型(UIUserNotificationActionBehaviorTextInput),通过behavior来设置(只有iOS9才拥有的属性)。回调的方法iOS9使用了两个新的回调方法来处理点击按钮的事件:
- (void)application:(UIApplication *)application handleActionWithIdentifier:(nullableNSString *)identifier forLocalNotification:(UILocalNotification *)notification withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void(^)())completionHandler NS_AVAILABLE_IOS(9_0)
- (void)application:(UIApplication *)application handleActionWithIdentifier:(nullableNSString *)identifier forRemoteNotification:(NSDictionary *)userInfo withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void(^)())completionHandler NS_AVAILABLE_IOS(9_0)
当Action为UIUserNotificationActionBehaviorTextInput时,需要通过responseInfo的UIUserNotificationActionResponseTypedTextKey来获取输入的文字内容,UIUserNotificationTextInputActionButtonTitleKey获取点击的按钮类型.
当Action为UIUserNotificationActionBehaviorDefault时,responseInfo为nil,通过identifier来区分点击按钮分别是什么来做处理.
客户端设置
设置带有快速回复内容的通知
#ifdef __IPHONE_9_0
UIMutableUserNotificationAction *replyAction = [[UIMutableUserNotificationAction alloc]init];
replyAction.title = @&Reply&;
replyAction.identifier = @&comment-reply&;
replyAction.activationMode = UIUserNotificationActivationModeB
replyAction.behavior = UIUserNotificationActionBehaviorTextI
UIMutableUserNotificationCategory *category = [[UIMutableUserNotificationCategory alloc]init];
category.identifier = @&reply&;
[category setActions:@[replyAction] forContext:UIUserNotificationActionContextDefault];
使用回调函数
- (void)application:(UIApplication *)application handleActionWithIdentifier:(nullable NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void(^)())completionHandler NS_AVAILABLE_IOS(9_0) {
if ([identifier isEqualToString:@&comment-reply&]) {
NSString *response = responseInfo[UIUserNotificationActionResponseTypedTextKey];
//对输入的文字作处理
completionHandler();
服务端设置
服务端payload格式:aps增加category字段,当该字段与客户端UIMutableUserNotificationCategory的identifier匹配时,触发设定的action和button显示。
payload example:
{&aps&:{&alert&:&example&, &sound&:&default&, &badge&: 1, &category&:&reply&}}
iOS 8 UILocalNotification
本次iOS 8 UILocalNotification增加了三个参数: region、regionTriggersOnce、category。
region: 用于控制当用户进入或者离开某一个地理位置时候,触发通知。使用此功能,用户需要拥有CoreLocation的&when-in-use&权限。regionTriggersOnce(BOOL):当为YES时,通知只会触发一次,当为NO时,通知将会在每一次进入或者离开时都触发。category:如果localNotification通过+[UIUserNotificationSettings settingsForUserNotificationTypes:userNotificationActionSettings:]注册了,通过该category可以获取该通知的注册category.
客户端设置
使用UILocalNotification
// set localNotification
CLLocationCoordinate2D coordinate2D;
coordinate2D.latitude = 100.0;
coordinate2D.longitude = 100.0;
CLRegion *currentRegion =
[[CLCircularRegion alloc] initWithCenter:coordinate2D
radius:CLLocationDistanceMax
identifier:@&test&];
[APService setLocalNotification:[NSDate dateWithTimeIntervalSinceNow:120]
alertBody:@&test ios8 notification&
alertAction:@&取消&
identifierKey:@&1&
userInfo:nil
soundName:nil
region:currentRegion
regionTriggersOnce:YES
category:@&test&];
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:99017次
积分:1911
积分:1911
排名:第17922名
原创:84篇
转载:66篇
评论:14条
(1)(5)(2)(4)(12)(4)(2)(10)(11)(5)(3)(1)(5)(5)(2)(1)(3)(23)(35)(17)Ionic 集成 jpush(极光推送)之 IOS 篇 - Ionichina
小学生·董宏飞
Ionichina 社区街道办事处 主任
发布于 2年前
35308 次浏览
Ionic 集成 jpush(极光)推送之 IOS 篇
极光推送官方版的 phonegap 插件在。
由于官方版插件 ios 版暂时没有打开通知的方法,所以在官方基础上修改了下,修改后的插件放在了,下面说明以修改后的插件为准。(感谢极光官方大神viper耐心帮助,同时也参考了下大神的项目)
极光账户设置部分可以参考小和尚的分享。
下面主要说明项目代码部分修改。
新建一个 ionic项目
$ ionic start --id com.ionichina.ionicjpush ionic_jpush tabs
注:修改 id 为自己应用的 Bundle identifier
添加 IOS 平台
$ cd ionic_jpush
$ ionic platform add ios
$ ionic plugin add /DongHongfei/jpush-phonegap-plugin.git
等待时间比较长,你也可以像小和尚里介绍的先下载下来,再安装,但这个过程是跑不了的
(接下来,蛋疼的事情开始了)
修改: ionic_jpush\plugins\cn.jpush.phonegap.JPushPlugin\src\ios\PushConfig.plist
修改对应的APP_KEY和CHANNEL(渠道)
确保有如下代码,不然后面 Xcode 运行会警告:
&key&APS_FOR_PRODUCTION&/key&
&string&0&/string&
在 js 中添加通知实现
在 app.js 最后添加一个 push 工厂(参考了 大神的项目)
.factory('Push', function() {
setBadge: function(badge) {
if (push) {
console.log('jpush: set badge', badge);
plugins.jPushPlugin.setBadge(badge);
setAlias: function(alias) {
if (push) {
console.log('jpush: set alias', alias);
plugins.jPushPlugin.setAlias(alias);
check: function() {
if (window.jpush && push) {
plugins.jPushPlugin.receiveNotificationIniOSCallback(window.jpush);
window.jpush =
init: function(notificationCallback) {
console.log('jpush: start init-----------------------');
push = window.plugins && window.plugins.jPushP
if (push) {
console.log('jpush: init');
plugins.jPushPlugin.init();
plugins.jPushPlugin.setDebugMode(true);
plugins.jPushPlugin.openNotificationInAndroidCallback = notificationC
plugins.jPushPlugin.receiveNotificationIniOSCallback = notificationC
在 app.js 的 run 函数里定义通知回调函数
记得在 run 函数里引用 Push 先
// push notification callback
var notificationCallback = function(data) {
console.log('received data :' + data);
var notification = angular.fromJson(data);
//app 是否处于正在运行状态
var isActive = notification.
// here add your code
if (ionic.Platform.isIOS()) {
window.alert(notification);
//非 ios(android)
$ionicPlatform.ready 里进行初始化
Push.init(notificationCallback);
//设置别名
Push.setAlias(&&);
编译 IOS 项目
$ ionic build ios
(接下来,更蛋疼的事情开始了)
修改配置 IOS 项目(不要问我为啥)
修改 AppDelegate.m,
#import &APService.h&
#import &JPushPlugin.h&
didFinishLaunchingWithOptions函数中添加
// Required
#if __IPHONE_OS_VERSION_MAX_ALLOWED & __IPHONE_7_1
if ([[UIDevice currentDevice].systemVersion floatValue] &= 8.0) {
//可以添加自定义categories
[APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
//categories 必须为nil
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
//categories 必须为nil
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
// Required
[APService setupWithOption:launchOptions];
didRegisterForRemoteNotificationsWithDeviceToken中添加
// Required
[APService registerDeviceToken:deviceToken];
[APService setDebugMode];
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
// Required
[APService handleRemoteNotification:userInfo];
if (application.applicationState == UIApplicationStateActive) {
isActive = TRUE;
isActive = FALSE;
NSDictionary *dict=[[NSMutableDictionary alloc] initWithDictionary:userInfo];
[dict setValue: [[NSNumber alloc] initWithBool:isActive] forKey:@&isActive& ];
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPlugReceiveNotificaiton
object:dict] ;//viper
OC 代码算是完事儿,然后就是配置
修改项目 Capabilities,打开 Background Modes,勾选最后一项Remote notications
设置证书,这个就不教了,网上一大堆
Xcode 这边就算配置完了
接下就是设置一些Xcode常规操作,编译运行,从极光官方控制台发送一条通知,然后查看Xcode控制台,应该就会有推送的通知数据打印了。
下面的事儿你自己应该搞的定。
示例代码我放在了。
收了备用 辛苦了~
Dong牛人, 感谢你的教程! 如久旱逢甘霖啊! 辛苦!
我擦,我只是个小学生而已啊~
Dong牛人, 如图所示, 蓝色部分的信息我在客户端如何用js得到啊, 请指教, 不胜感激!
notificationCallback函数里的data就包含了推送过来的消息了,你可以本地跑起来,然后打印下日志具体看看就明白了
问题解决了, 是我误解了, 我声明了如下函数, 结果用了console.log来打信息, 还期望在xcode的console里看到信息, 其实应该是用safari里的console来看, 谢谢!
window.plugins.jPushPlugin.receiveMessageIniOSCallback = function (data) {
console.log(‘abc’);
console.log(&receiveMessageIniOSCallback & + data);
} catch (exception) {
console.log(&receiveMessageIniOSCallback & + exception);
能帮上我的忙就是牛人
兄弟, 我刚刚发现Push.setAlias在你github: 上的插件中已经失效了, 我看了下上的15天前更新过, 不知道是不是这个是导致的原因, 我正在痛苦排查中, 你有线索请告知我下, 谢谢!
我换回了官方的, 可以正常setAlias了, 不过一个细节是: 我根据官方的readme, 做了cordova plugin add org.apache.cordova.device, 不知道是不是由于做了这个导致可以正常使用setAlias的, 仅供参考
不过官方文档中的如图高亮部分似乎不对, 这个函数是后来加上去的:
org.apache.cordova.device应该默认就有的,官方最新版倒是没试过,不过按说应该是完善了之前的问题的
兄弟能教我下在官方的的基础上添加JPushPlugin.prototype.receiveNotificationIniOSCallback的步骤么?正在摸索中, 谢谢!
这个就爱莫能助了,需要有 object-c 基础才行,之前我是在官方的viper帮助下添加的。
不过我看这里的文档上有方法啊,我没有试,这个方法不好使么?
在你需要接收通知的的js文件中加入:
document.addEventListener(&jpush.receiveNotification&, onReceiveNotification, false);
onOpenNotification需要这样写:
var onReceiveNotification = function(event){
= event.aps.
console.log(&JPushPlugin:onReceiveNotification key aps.alert:&+alert);
catch(exeption){
console.log(exception)
类似这种调用方法呢:
我尝试成功了
//app在前台运行中
document.addEventListener(&jpush.receiveNotification&, function(event) {});
//app在后台
document.addEventListener(“jpush.openNotification&, function(event) {});
这两个可以在ios捕捉到发来的&通知”
感谢兄弟的一路陪伴, 祝论坛越办越好
就是oc调用javascript嘛,java和oc都是可以调用javascript引擎的
app前台,后台指那个地方,我监听不到
如果正在微信中看朋友圈, 或打字, 就是指微信这个app在前台运行中, 如果你现在在手机上正在用其他app(如正在用陌陌约…), 那么微信app就在后台
之所以提问,前/后台问题,是因为,我的 app 在 android 手机上,能收到消息,但打开时捕捉不到 :(
能帮我诊断下吗?
.factory('Pusher', function ($cordovaDialogs, $localStorage) {
var pusher =
onReceiveMessage: function (event) {
if(pusher){
$cordovaDialogs.alert(pusher.receiveMessage.message);
onOpenNotification: function (event) {
var alert =
if(pusher && pusher.openNotification.alert){
alert = pusher.openNotification.
alert = event.aps.
$cordovaDialogs.alert(alert);
onReceiveNotification: function (event) {
$cordovaDialogs.alert(event);
getRegistradionID: function () {
return $localStorage.get('jPushID', null);
init: function () {
if (window.plugins && window.plugins.jPushPlugin) {
pusher = window.plugins.jPushP
pusher.init();
// 获取注册ID
pusher.getRegistrationID(function (id) {
$localStorage.set('jPushID', id);
if (ionic.Platform.isAndroid()){
pusher.setDebugModeFromIos();
pusher.setApplicationIconBadgeNumber(0);
pusher.setDebugMode(true);
$ionicPlatform.ready(function() {
Pusher.init();
// 获取通知内容
document.addEventListener(&jpush.openNotification&, Pusher.onOpenNotification, false);
// 获取自定义消息推送内容
document.addEventListener(&jpush.receiveMessage&, Pusher.onReceiveMessage, false);
// 获取通知内容
document.addEventListener(&jpush.receiveNotification&, Pusher.onReceiveNotification, false);
使用plugins.jPushPlugin.setApplicationIconBadgeNumber(0)无法消除icon上的badge,请问大家遇到过这个问题么,有什么思路么,谢谢
你试试官方的window.plugins.jPushPlugin.setApplicationIconBadgeNumber(badge)呢?
也不行,一样的错误
[jpush]: reset badge
12:00:34.649 mypush[742:60b] ERROR: Method ‘setApplicationIconBadgeNumber:’ not defined in Plugin ‘JPushPlugin’
12:00:34.651 mypush[742:60b] -[CDVCommandQueue executePending] [Line 159] FAILED pluginJSON = [&JPushPlugin&,&JPushPlugin&,&setApplicationIconBadgeNumber&,[0]]
12:00:34.853 mypush[742:5207] JPushLog: set badge:0 succeed
不明白为什么,官方文档也写着有这个函数的
不知道官方推出的推送服务
能不能够取代极光推送?
可以的,但是后面会收费,具体收费模式未定
设置别名可以,我在Push工厂里添加了设置标签setTags方法,为什么客户端无法设置标签呢,服务器端调用的时候就出现1011 cannot find user by this audience
plugins.jPushPlugin.setTags(tag);
插件设置tag就会出错
[__NSCFString count]: unrecognized selector sent to instance 0x15dc12e0
10:03:20.604
*** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate:
&NSInvalidArgumentException& -[__NSCFString count]: unrecognized selector sent to instance 0x15dc12e0
5.0中好像默认不存在这个东东
问个问题啊
为什么我的回调方法总是失败
总提示这个application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.
能帮我解答下吗?谢谢
本人ios菜鸟
您好,我想请教下在申请证书的时候,要填写Bundle ID,这个要填写ionic项目里的哪个呢?谢谢您
您好,集成里以后,在模拟器上运行ionic iOS 可以接收到推送吗
您好,能请教下怎么后台缓存推送消息吗,我目前只找到了点击推送消息时处理推送消息,没找到后台接收到消息就缓存下来的方法,所以想请教下怎么后台处理收到的推送消息,还请不吝赐教。
服务器赞助商为
存储赞助商为
,由提供应用性能服务。

我要回帖

更多关于 极光推送ios 使用说明 的文章

 

随机推荐