请问极光推送服务端sdk发送消息时能指定发到android还是ios吗?


(myplxdm) #1

请问极光推送服务端sdk发送消息时能指定发到android还是ios吗?如果能在哪里指定平台?


(12) #2

Platform 这个字段指定
https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#platform


(myplxdm) #3

请问在极光推送后台中的可选项要在代码中怎么设置?
我想发给ios 时设置mutable-content 选项要怎么设置?

public static PushResult sendIosPush(String alias,String msg) {
		JSONObject param=new JSONObject();
		JSONObject body=new JSONObject();
		body.put("alert","");
		body.put("badge",0);
		body.put("sound","");
		body.put("mutable-content","1");
		param.put("aps",body);
		PushPayload payload =buildPushNotifyMessage(alias,param,msg);
		try {
			return jPushClient.sendPush(payload);
		} catch (APIConnectionException | APIRequestException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static PushPayload buildPushNotifyMessage(String alias,JSONObject obj,String msg) {
		 return PushPayload.newBuilder()
	                .setPlatform(Platform.all())
	                .setAudience(Audience.alias(alias))
	                .setNotification(Notification.alert(obj.toCompactString()))
	                .setMessage(Message.content(msg))
	                .build();
   }

(12) #4

可选项,extra ,在 Notification - iOS 或 Android 具体的属性下有 extra 字段。

mutable-content 一样
参考 example


(myplxdm) #5

以下错误是什么意思?ios平台
2018-11-08 11:11:41.468628+0800 spvoice[2641:217580] CredStore - performQuery - Error copying matching creds. Error=-25300, query={
class = inet;
“m_Limit” = “m_LimitAll”;
ptcl = htps;
“r_Attributes” = 1;
sdmn = “sync.im.jiguang.cn”;
srvr = “sync.im.jiguang.cn”;
sync = syna;
}
2018-11-08 11:11:41.591321+0800 spvoice[2641:217578] | JIGUANG | I - [JMSGHttpManager] convert error is Error Domain=jmsg_error Code=898008 “basic authentication failed” UserInfo={NSLocalizedDescription=basic authentication failed}
2018-11-08 11:11:41.858507+0800 spvoice[2641:217580] | JIGUANG | W - [JIGUANGMessageCenter] Found repeated message, and throw it away - msgId:1990330339
2018-11-08 11:11:41.956429+0800 spvoice[2641:217580] | JIGUANG | W - [JIGUANGMessageCenter] Found repeated message, and throw it away - msgId:2638054350
2018-11-08 11:11:42.078533+0800 spvoice[2641:217580] | JIGUANG | W - [JIGUANGMessageCenter] Found repeated message, and throw it away - msgId:862750580
2018-11-08 11:11:42.159170+0800 spvoice[2641:217580] | JIGUANG | W - [JIGUANGMessageCenter] Found repeated message, and throw it away - msgId:1990607434
2018-11-08 11:11:42.261580+0800 spvoice[2641:217580] | JIGUANG | W - [JIGUANGMessageCenter] Found repeated message, and throw it away - msgId:862808185


(12) #6

你这是在什么情况下出现的?

这里的 898008 的 JMessage 的报错
898008 Basic authentication failed. 校验失败

给完整的日志信息


(myplxdm) #7
2018-11-08 11:13:57.825483+0800 spvoice[2692:218544] JMSGReceiver loadReceiver
2018-11-08 11:13:57.870167+0800 spvoice[2692:218544] [framework] CUIThemeStore: No theme registered with id=0
2018-11-08 11:13:57.872214+0800 spvoice[2692:218549]  | JIGUANG | I - [JMessage] this is official version SDK.
2018-11-08 11:13:57.909952+0800 spvoice[2692:218544] Unknown class ViewController in Interface Builder file.
2018-11-08 11:13:57.929838+0800 spvoice[2692:218569]  | JIGUANG | I - [JIGUANGService] 
--------------------------- JPush Log ----------------------------
--------------------JPush SDK Version:3.1.0--build:64----------
--------------------JCore Lib Version:1.2.2--build:60----------
-----------------AppKey:349c46bc803798c4cf6a5839----------------
----------------------------------------------------------------
2018-11-08 11:13:57.931931+0800 spvoice[2692:218581]  | JIGUANG | I - [JMSGClientController] 
------------------- JMessage SDK --------------------
------------- JMessage SDK version:3.6.1, build:222 ---------
------------- JCore Lib Version:1.2.2, build:60 ---------
------------- AppKey:349c46bc803798c4cf6a5839 ---------
---------------------------------------------------------
2018-11-08 11:13:57.939151+0800 spvoice[2692:218569]  | JIGUANG | I - [JIGUANGClientController] Action - jpush setup
2018-11-08 11:13:57.943129+0800 spvoice[2692:218569]  | JIGUANG | I - [JIGUANGClientController] Action - setup
2018-11-08 11:13:58.098951+0800 spvoice[2692:218568]  | JIGUANG | I - [JMSGClientController] Action - jmessage setup
2018-11-08 11:13:58.286732+0800 spvoice[2692:218569]  | JIGUANG | I - [JIGUANGSessionController] connecting with coreAddr 121.46.20.61,port 7005
2018-11-08 11:13:58.840196+0800 spvoice[2692:218569]  | JIGUANG | I - [JIGUANGLogin] 
----- login result -----
uid:15756648856 
registrationID:121c83f7600c8de2e2f 
idc:1
2018-11-08 11:13:58.980540+0800 spvoice[2692:218573] Reachability Flag Status: -R ------- networkStatusForFlags
2018-11-08 11:13:59.050830+0800 spvoice[2692:218549]  | JIGUANG | I - [JMSGUser+JMSGInner] report sdkversion success
2018-11-08 11:13:59.091177+0800 spvoice[2692:218549]  | JIGUANG | I - [JIGUANGBadgeNumberReport] set badge:0 succeed
2018-11-08 11:13:59.116370+0800 spvoice[2692:218568]  | JIGUANG | I - [JMSGBadgeNumberReport] set badge:0 succeed
2018-11-08 11:13:59.149245+0800 spvoice[2692:218552]  | JIGUANG | I - [JMessage+JMSGInner] Action - jmsg_clearCurrentUser
2018-11-08 11:13:59.151037+0800 spvoice[2692:218552]  | JIGUANG | I - [JMSGUser] tcp login user success, user =  <JMSGUser, 0x2819cc870> - [ARRAY - uid:180158050, username:xxx, nickname:<null>, noteName:<null>, noteText:<null>, gender:0, birthday:<null>, avatar:<null>, region:<null>, siganature:<null>, address:<null>, createTime:<null>, extras:<null>, appKey:349c46bc803798c4cf6a5839]
2018-11-08 11:13:59.158327+0800 spvoice[2692:218544] (null)
2018-11-08 11:14:00.017824+0800 spvoice[2692:218569]  | JIGUANG | W - [JIGUANGMessageCenter] Found repeated message, and throw it away - msgId:2638275290

(12) #8

这个日志看起来都是成功的,注册成功,登陆成功,你需要咨询的是什么


(myplxdm) #9

就是上上个日志有一段提示错误的那个是什么原因提示的?因为中途有重开过程序,所以日志不完整。

return PushPayload.newBuilder()
		            .setPlatform(Platform.ios())
		            .setAudience(Audience.alias(alias))
		            .setNotification(Notification.newBuilder()
		                    .addPlatformNotification(IosNotification.newBuilder()
		                            .setAlert("1")
		                            .setBadge(5)
		                            .setMutableContent(true)
		                            .setSound("happy")
		                            .addExtra("mutable-content", "1")
		                            .build())
		                    .build())
		             .setMessage(Message.content("1")) //去掉一样没效果
		             .setOptions(Options.newBuilder()
		                     .setApnsProduction(true)
		                     .build())
		             .build();

按这样发送,ios端可以接收到消息,但是无法拦截,但是用极光后台发送就可以拦截


(12) #10

你要怎么拦截?如何判断的

提供你 API 推送出去的消息的 MessageID和官网的 MessageID 和你的 Appkey


(myplxdm) #11

用UNNotificationServiceExtension来拦截
msgid 3451201962
appkey 349c46bc803798c4cf6a5839

官网msgid 1998837586


(12) #12

API这条消息就没有发成功,你发的是生产的消息,而官网发的是开发的消息,你 App是开发环境的。

API推送消息给iOS,需要指定推送的环境!请让后台修改apns_production,false是开发,true是生产。


(myplxdm) #13
JSONObject body=new JSONObject();
		body.put("sound","default");
		body.put("badge",1);
		body.put("mutable-content",1);
		 return PushPayload.newBuilder()
		            .setPlatform(Platform.ios())
		            .setAudience(Audience.alias(alias))
		            .setNotification(Notification.newBuilder()
		                    .addPlatformNotification(IosNotification.newBuilder()
		                            .setAlert("1")
		                            .setBadge(5)
		                            .setMutableContent(true)
		                            .setSound("happy")
		                            .addExtra("ios",body.toCompactString())
		                            .build())
		                    .build())
		             .setMessage(Message.content("1"))
		             .setOptions(Options.newBuilder()
		                     .setApnsProduction(false) //已经设置是开发环境
		                     .build())
		             .build();

消息id : 2746620368
但还是收不到?是不是还有什么设置不正确?


(12) #14

你消息是成功收到了吧?通知栏上有通知了?

你如何判断的没有被 UNNotificationServiceExtension拦截?

你 API 实际推送出去的消息是
notification {“ios”:{“alert”:“1”,“badge”:“5”,“extras”:{“mutable-content”:“1”},“mutable-content”:true,“sound”:“happy”}}


(myplxdm) #15

通知是有发送出去,ios可以收通知,但是没有被扩展拦截,但是用极光后台是可以拦截的,我主要是要实现拦截后处理信息,是不是mutable-content的位置不对?


(12) #16

这个值传的没有什么问题,关键是你们怎么判断的没有被拦截?方法没走?你们官网处理消息后结果是什么?

你们官网应该还推送了一个 title 字段的信息。

客户端 仿照 demo 在推送送达的时候改变一下 title,来确认此方法到底有没有走

你是运行的 ServiceExtension Target 还是主 target

iOS11 断点调试 extension 是有问题的,正常使用没有问题。最好用 iOS10 或者 iOS12 来调试


(myplxdm) #17

扩展里会把接收到的title播放出来,如果没拦截到就没有声音,用后台都可以播放出声音,我测试的手机是ios12版本


(12) #18

那你API 推送的时候没有传title 给你的设备呀。