在线求助啊,集成ios极光推送集成教程不走收到通知的方法

【极光推送】给指定用户发送消息 - 博客频道 - CSDN.NET
陕西易唐云网智能科技有限公司
分类:jpush
&1.&你可以在极光推送官方文档中,找到相关平台的SDK集成方式,链接为:2.&具体的SDK集成方式再次不做赘述,因为笔者不是专业的移动开发人士,甚至连服务器开发也是临时凑热闹搭把手而已。&三、&客户端开发想要实现给指定人群推送消息的功能,首先要对推送人群方式进行一个简单的了解。深入的内容可以参考社区中的《推送人群的选择 – 技术篇》文章,地址是/push_audience_tech/。&这里只是对具体场景应用简单描述,设计一下。我们的消息分为三类,一类是通知消息,给所有人。另一类是具体的工作安排,给某一部门的人。还有一类是具体的个人消息,如给领导发请假通知等。所以我们最终决定使用的方式包括一下方式:1) 广播:顾名思义就是给所有人群发消息2) 别名(alias):给指定id的终端设备发送消息。别名需要客户端进行设置。3) 标签(tag):分组发送消息,理解起来应该类似于微信建了一个群聊的赶脚。标签需要客户端进行设置。&客户端开发步骤简述1. 集成SDK(之前已经完成)2. 启动后,到服务器上注册,并获取注册ID(RegistrationID)3. 调用Method -&setAliasAndTags (with&Callback)函数完成别名和标签的设置。&注1:这里,我们应用的别名就是员工ID,标签就是部门ID。以此来进行分类推送注2:具体的参数定义可参照官方文档《》一文。链接地址为:注3:只有call back返回0时才设置成功,其他结果均会让服务器返回1011错误。&四、&服务端开发1.&设置推送平台setPlatform(Platform.all()) //设置所有平台setPlatform(Platform.android())//设置androidsetPlatform(Platform.android_ios())//设置Android和iOSsetPlatform(Platform.ios())//设置iOS&2.&设置受众(收到推送消息的人群)setAudience(Audience.all())设置所有受众setAudience(Audience.tag("tag1","tag2"))//设置tag为tag1,tag2的受众,群发setAudience(AudienceTarget.alias("alias1", "alias2")) //设置别名alias为alias1,alias2的受众,单发注1: 更多的发送方式,可以到官网上去找文档,可以这是多个条件混合发送。由于本项目中没有那么复杂的应用需求,所以此处省略不提。&3.&设置通知方式setNotification(Notification.alert(ALERT)) //设置通用通知,以alert方式提醒setNotification(Notification.android(ALERT, TITLE, null))//增加标题setNotification(Notification.newBuilder()&&&&&&&&&&&&&&&&&&&.addPlatformNotification(IosNotification.newBuilder()&&&&&&&&&&&&&&&&&&&.setAlert(ALERT)&&&&&&&&&&&&&&&&&
&.setBadge(5)&&&&&&&&&&&&&&&&&&&&.setSound("happy")&&&&&&&&&&&&&&&&&&&&.addExtra("from", "JPush")&&&&&&&&&&&&&&&&&&&&.build())&&&&&&&&&&&&&&&&&&&&.build())//不管什么东西,iOS的总要复杂一些。注1: 可以不设置通知方式,让其使用默认的通知方式进行消息推送&4.&设置通知内容setMessage(Message.content(MSG_CONTENT))//MSG_CONTENT中就是通知内容。5.&设置控制选项setOptions(M\options(sendno, time_to_live, override_msg_id, apns_production,big_push_duration))&当前包含如下几个可选项:sendno&int&可选&推送序号&纯粹用来作为 API 调用标识,API 返回时被原样返回,以方便 API 调用方匹配请求与返回。time_to_live&int&可选&离线消息保留时长&推送当前用户不在线时,为该用户保留多长时间的离线消息,以便其上线时再次推送。默认 86400 (1 天),最长 10 天。设置为 0 表示不保留离线消息,只有推送当前在线的用户可以收到。override_msg_id&long&可选&要覆盖的消息ID&如果当前的推送要覆盖之前的一条推送,这里填写前一条推送的 msg_id 就会产生覆盖效果,即:1)该 msg_id 离线收到的消息是覆盖后的内容;2)即使该 msg_id Android 端用户已经收到,如果通知栏还未清除,则新的消息内容会覆盖之前这条通知;覆盖功能起作用的时限是:1 天。 如果在覆盖指定时限内该 msg_id 不存在,则返回 1003 错误,提示不是一次有效的消息覆盖操作,当前的消息不会被推送。apns_production&boolean&可选&APNs是否生产环境& True 表示推送生产环境,False 表示要推送开发环境; 如果不指定则为推送生产环境。注:JPush 官方 API LIbrary (SDK) 默认设置为推送 “开发环境”。big_push_duration&int&可选&定速推送时长(分钟)&又名缓慢推送,把原本尽可能快的推送速度,降低下来,在给定的 n 分钟内,均匀地向这次推送的目标用户推送。最大值为 1440。未设置则不是定速推送。&6.&开始推送sendPush(PushPayload类型参数)&7.&获取返回结果PushResult类型参数,可以回去到返回值。结果大致格式如下:{"msg_id":,"sendno":}8. 附上两段分标签以及分别名推送的函数代码//description:自定义推送函数--分组推送//createTime: 04-21//author: xk
public static PushPayload buildPushObject_android_and_iosByTag(String tag,String title,String content) {
return PushPayload.newBuilder()
.setPlatform(Platform.android_ios())
.setAudience(Audience.tag(tag))
.setNotification(Notification.newBuilder()
.setAlert(content)
.addPlatformNotification(AndroidNotification.newBuilder()
.setTitle(title).build())
.addPlatformNotification(IosNotification.newBuilder()
.incrBadge(1)
.addExtra(title, content).build())
}//description:自定义推送函数--按别名推送//createTime: 04-21//author: xk
public static PushPayload buildPushObject_android_and_iosByAlias(String alias,String title,String content) {
return PushPayload.newBuilder()
.setPlatform(Platform.android_ios())
.setAudience(Audience.alias(alias))
.setNotification(Notification.newBuilder()
.setAlert(content)
.addPlatformNotification(AndroidNotification.newBuilder()
.setTitle(title).build())
.addPlatformNotification(IosNotification.newBuilder()
.incrBadge(1)
.addExtra(title, content).build())
xuexiiphone
排名:第18705名
(14)(31)(1)(1)(2)(4)(4)(4)(19)(3)(2)(4)(31)(3)(2)(20)(8)(7)(1)(5)(1)(2)(1)(1)(1)(6)(10)(4)(1)(3)在线求助啊,集成极光推送不走收到通知的方法_百度知道114网址导航当前位置:
& Swift - JPush极光推送的使用7(发送自定义消息)
Swift - JPush极光推送的使用7(发送自定义消息)
发布:hangge
我之前的一系列文章讲的都是发送通知的相关内容。JPush极光推送除了可以推送通知,还可以用来发送自定义消息。本文接着介绍下后者。
1,发送自定义消息与发送通知的异同
(1)客户端App只有在运行的时候才能收到自定义消息。而通知不同,不管客户端是否在运行都是能够收到推送过来的通知。
(2)发送自定义消息的话不需要通过 APNs,但相较于通知,可以发送更多的内容(当然还是有长度限制的)。
(3)虽然App退出后就没法收到自定义消息,但 JPush 服务器这时会将其保存成离线消息(具体保留时长可以设置)。当App启动后,会自动获取到这条离线消息。
(4)由于发送自定义消息不需要通过 APNs,且客户端在运行时才能接收。所以比较适合用在在线聊天室、即时通讯等相关应用上。
(5)同发送通知一样,发送自定义消息也可以根据别名、标签发送给指定用户,或者广播的形式发给所有人。&
(6)自定义消息同样可以定时发送。
2,自定义消息的样例
(1)服务端页面上填写消息内容,点击“发送”。即可将自定义消息发送到客户端。
(2)客户端如果是运行状态,则会接收到并进行下一步处理(这里直接将收到的自定义消息弹出显示。)如果客户端此刻没有在运行,等客户端下次运行时也会收到之前发送的这条信息。
3,样例代码
(1)客户端代码:AppDelegate.swift
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)
//通知类型(这里将声音、消息、提醒角标都给加上)
let userSettings = UIUserNotificationSettings(forTypes: [.Badge, .Sound, .Alert],
categories: nil)
if ((UIDevice.currentDevice().systemVersion as NSString).floatValue &= 8.0) {
//可以添加自定义categories
JPUSHService.registerForRemoteNotificationTypes(userSettings.types.rawValue,
categories: nil)
//categories 必须为nil
JPUSHService.registerForRemoteNotificationTypes(userSettings.types.rawValue,
categories: nil)
// 启动JPushSDK
JPUSHService.setupWithOption(nil, appKey: "7becfd",
channel: "Publish Channel", apsForProduction: false)
//监听自定义消息的接收
let defaultCenter =
NSNotificationCenter.defaultCenter()
defaultCenter.addObserver(self, selector: #selector(networkDidReceiveMessage(_:)),
name:kJPFNetworkDidReceiveMessageNotification, object: nil)
return true
//收到自定义消息
func networkDidReceiveMessage(notification:NSNotification){
var userInfo =
notification.userInfo!
//获取推送内容
let content =
userInfo["content"] as! String
//获取服务端传递的Extras附加字段,key是自己定义的
//let extras =
userInfo["extras"]
as! NSDictionary
//let value1 =
extras["key1"] as! String
//显示获取到的数据
let alertController = UIAlertController(title: "收到自定义消息",
message: content,
preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "确定", style: .Cancel, handler: nil))
self.window?.rootViewController!.presentViewController(alertController,
animated: true, completion: nil)
func application(application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
//注册 DeviceToken
JPUSHService.registerDeviceToken(deviceToken)
func application(application: UIApplication,
didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -& Void) {
//增加IOS 7的支持
JPUSHService.handleRemoteNotification(userInfo)
completionHandler(UIBackgroundFetchResult.NewData)
func application(application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: NSError) {
NSLog("did Fail To Register For Remote Notifications With Error: \(error)")
//...................
(2)服务端代码:index.php
//引入代码
require_once("./JPush/JPush.php");
if(isset($_POST["message"])){
$app_key = "7bec7195798fd";
$master_secret = "32da406dc7b25da2c9828";
$client = new JPush($app_key, $master_secret);
//简单的消息发送样例
$result = $client-&push()
-&setPlatform(array('ios', 'android'))
-&addAllAudience()
-&setMessage($_POST["message"], null, null, null)
-&setOptions(null, null, null, false)
echo 'Result=' . json_encode($result);
&form action="index.php" method="post"&
消息:&input type="text" name="message"/&
&button type="submit"&发送&/button&
4,更完整的发送样例
同推送通知一样,发送自定义消息也可以添加附加字段,以及定时发送。
// 发送自定义消息
$payload = $client-&push()
-&setPlatform(array('ios', 'android'))
-&addAllAudience()
-&setMessage("msg content", 'msg title', 'type', array("key1"=&"value1", "key2"=&"value2"))
-&setOptions(null, null, null, false)
-&build();
// 创建在指定时间点触发的定时任务
$response = $client-&schedule()-&createSingleSchedule("指定时间点的定时任务",
$payload, array("time"=&" 14:35:00"));
echo 'Result=' . json_encode($response);

我要回帖

更多关于 ionic集成极光推送 的文章

 

随机推荐