给 iOS 平台推送 title 值失败


(北执) #1


根据这帖子写无法成功


iOS设置推送标题 title 和subtitle
#2

上述方法都是经过测试的,请说明你现在用的什么语言的SDK,怎么写的代码!如果错误了,报了什么错!


(北执) #3
   IosAlert iosAlert = IosAlert.newBuilder()
                   .setTitleAndBody("test alert", "subtitle", "test ios alert json")
                   .setActionLocKey("PLAY")
                   .build();
               
               PushPayload payload = PushPayload  
               .newBuilder()  
               .setPlatform(Platform.all())  
               .setAudience(Audience.alias(pushMsg.getAlias()))//Audience.alias(alias.replace(".", "_"))  
               .setNotification(  
                       Notification  
                               .newBuilder()  
                               .addPlatformNotification(  
                                       IosNotification.newBuilder()  
                                               .setAlert(iosAlert)//notification
                                               .setSound("happy.caf")
                                               .addExtras(pushMsg.getExtras())//extras
                                               .build())

#4

你这样推送的结果是什么?你的 Java SDK 的版本多少?


(北执) #5

Java 8.0


(北执) #6
  PushPayload payload = PushPayload  
               .newBuilder()  
               .setPlatform(Platform.all())  
               .setAudience(Audience.alias(pushMsg.getAlias()))//Audience.alias(alias.replace(".", "_"))  
               .setNotification(  
                       Notification  
                               .newBuilder()  
                               .addPlatformNotification(  
                                       IosNotification.newBuilder()  
                                               .setAlert(iosAlert)//notification
                                               .setSound("happy.caf")
                                               .addExtras(pushMsg.getExtras())//extras
                                               .build())
                               /*.addPlatformNotification(  
                                       AndroidNotification.newBuilder()  
                                               .setAlert("这是什么鬼")//notification
                                               .setTitle(pushMsg.getTitle())
                                               .addExtras(pushMsg.getExtras())//extras
                                               .build())  */
                               .build())
                                      
                                       .setOptions(Options.newBuilder()
                                       .setApnsProduction(false)
                                       .build()).build();  
               PushResult result = jpushClient.sendPush(payload);

当我把Android给注释后,推成功了。问题是我要如何同时推给不同的平台?


(Josh Lipan) #7

如果要同时推送给ios和android平台,可以传Platform.android_ios()


#8

你不注释的情况下,推送会报错吗?报了什么错误?


(北执) #9

现在成功了。
我发现一个问题,如果推的太频繁会不成功,然后等一下又可以了。
你们频率做过限制么?


#10

报了什么错???

https://docs.jiguang.cn/jpush/server/push/server_overview/#api_1


(北执) #11

没有报任何错,就是推,连着推个五六次 就会没反应,然后等一下又可以推成功了


#12

你 Java SDK 换个方法:ApacheHttpClient 请求吧。
如果使用 NettyHttpClient,需要手动调用 close 方法退出进程,不建议使用他,如果创建大量线程,是可能导致堵塞的


(北执) #13

我项目用的是阿里的mq异步调用的。


#14

我说的是极光 SDK 里面的方法,跟你这个没什么关系额
用 ApacheHttpClient httpClient = new ApacheHttpClient(authCode, null, clientConfig);
https://github.com/jpush/jpush-api-java-client/blob/master/example/main/java/cn/jpush/api/examples/PushExample.java#L86


(北执) #15

按您说的添加了,推送成功,但是后台会报一个异常。

>  public boolean sendNotificationWithAlias(com.wybs.bbs.dal.model.JPushMsg pushMsg){
>            try {
>                ClientConfig clientConfig = ClientConfig.getInstance();
>                JPushClient jpushClient = new JPushClient(masterSecret, appKey);
>                String authCode = ServiceHelper.getBasicAuthorization(appKey, masterSecret);
>                ApacheHttpClient httpClient = new ApacheHttpClient(authCode, null, clientConfig);
>                jpushClient.getPushClient().setHttpClient(httpClient);
>                
>                IosAlert iosAlert = IosAlert.newBuilder()
>                    .setTitleAndBody(pushMsg.getTitle(), "", pushMsg.getAlert())
>                    .build();
>                
>                PushPayload payload = PushPayload  
>                .newBuilder()  
>                .setPlatform(Platform.android_ios())  
>                .setAudience(Audience.alias(pushMsg.getAlias()))//Audience.alias(alias.replace(".", "_"))  
>                .setNotification(  
>                        Notification  
>                                .newBuilder()  
>                                .addPlatformNotification(  
>                                        IosNotification.newBuilder()  
>                                                .setAlert(iosAlert)//notification
>                                                .setSound("default")
>                                                .addExtras(pushMsg.getExtras())//extras
>                                                .build())
>                                .addPlatformNotification(  
>                                        AndroidNotification.newBuilder()  
>                                                .setAlert(pushMsg.getAlert())//notification
>                                                .setTitle(pushMsg.getTitle())
>                                                .addExtras(pushMsg.getExtras())//extras
>                                                .build())
>                                .build())
>                                        .setOptions(Options.newBuilder()
>                                        .setApnsProduction(true)
>                                        .build()).build();  
>                PushResult result = jpushClient.sendPush(payload);
>                logger.debug("sendNotificationWithAlias() - push all - msgId={}, title={}, notification={}, alias={}, payload={}",result.msg_id, pushMsg.getTitle(), pushMsg.getAlert(), pushMsg.getAlias(), payload);
>                return result.isResultOK();
>            } catch (APIConnectionException e) {
>                logger.debug("APIConnectionException:"+e.getMessage());
>                e.printStackTrace();
>            } catch (APIRequestException e) {
>                logger.debug("APIConnectionException:"+e.getMsgId());
>                e.printStackTrace();
>            }
>            return false;
>       }

> **不影响推送成功,手机能接收到。**
>     >     [wybs-bbs-task] 2018-05-29 17:22:07.641 [ConsumeMessageThread_4] DEBUG [com.wybs.bbs.task.mq.listener.PushMessageListener:31] - consume() - the receive message - message=Message [topic=wybs_mq_test, systemProperties={__KEY=, __RECONSUMETIMES=0, __MSGID=C0A8019B25A018B4AAC29158FA470006, MIN_OFFSET=68, __TAG=qa_pushmessage, TAGS=qa_pushmessage, MAX_OFFSET=113}, userProperties={UNIQ_KEY=C0A8019B25A018B4AAC29158FA470006, MSG_REGION=cn-qingdao-publictest, TRACE_ON=true, CONSUME_START_TIME=1527585727641}, body=129]
>     >     [wybs-bbs-task] 2018-05-29 17:22:07.641 [ConsumeMessageThread_4] DEBUG [com.wybs.bbs.task.mq.listener.PushMessageListener:35] - consume() - the receive object - json={"title":"你对此问题的回答因违规已被屏蔽","alert":"5.12测试","alias":"1768177","extras":{"id":"126","type":"2"}}
>     >     [wybs-bbs-task] 2018-05-29 17:22:07.651 [ConsumeMessageThread_5] DEBUG [com.wybs.bbs.task.mq.listener.PushMessageListener:31] - consume() - the receive message - message=Message [topic=wybs_mq_test, systemProperties={__KEY=, __RECONSUMETIMES=0, __MSGID=C0A8019B25A018B4AAC29158FA700008, MIN_OFFSET=74, __TAG=qa_pushmessage, TAGS=qa_pushmessage, MAX_OFFSET=120}, userProperties={UNIQ_KEY=C0A8019B25A018B4AAC29158FA700008, MSG_REGION=cn-qingdao-publictest, TRACE_ON=true, CONSUME_START_TIME=1527585727651}, body=131]
>     >     [wybs-bbs-task] 2018-05-29 17:22:07.651 [ConsumeMessageThread_5] DEBUG [com.wybs.bbs.task.mq.listener.PushMessageListener:35] - consume() - the receive object - json={"title":"你对此问题的回答因违规已被屏蔽","alert":"初三初四","alias":"1768181","extras":{"id":"115","type":"2"}}
>     >     [wybs-bbs-task] 2018-05-29 17:22:07.654 [ConsumeMessageThread_6] DEBUG [com.wybs.bbs.task.mq.listener.PushMessageListener:31] - consume() - the receive message - message=Message [topic=wybs_mq_test, systemProperties={__KEY=, __RECONSUMETIMES=0, __MSGID=C0A8019B25A018B4AAC29158FA71000A, MIN_OFFSET=73, __TAG=qa_pushmessage, TAGS=qa_pushmessage, MAX_OFFSET=113}, userProperties={UNIQ_KEY=C0A8019B25A018B4AAC29158FA71000A, MSG_REGION=cn-qingdao-publictest, TRACE_ON=true, CONSUME_START_TIME=1527585727654}, body=118]
>     >     [wybs-bbs-task] 2018-05-29 17:22:07.655 [ConsumeMessageThread_6] DEBUG [com.wybs.bbs.task.mq.listener.PushMessageListener:35] - consume() - the receive object - json={"title":"你有 2 条回答因违规已被屏蔽","alert":" ","alias":"1768128","extras":{"id":"1768128","type":"5"}}
>     >     [wybs-bbs-task] 2018-05-29 17:22:07.683 [ConsumeMessageThread_4] WARN  [cn.jiguang.common.connection.ApacheHttpClient:398] - Got error response - responseCode:400, responseContent:{"msg_id": 65302200359439572, "error": {"message": "cannot find user by this audience", "code": 1011}}
>     >     [wybs-bbs-task] 2018-05-29 17:22:07.684 [ConsumeMessageThread_4] ERROR [cn.jiguang.common.connection.ApacheHttpClient:402] - Your request params is invalid. Please check them according to error message.
>     >     [wybs-bbs-task] 2018-05-29 17:22:07.684 [ConsumeMessageThread_4] DEBUG [com.wybs.bbs.task.service.JPushService:92] - APIConnectionException:65302200359439572
>     >     {}
>     >     	at cn.jiguang.common.connection.ApacheHttpClient.processResponse(ApacheHttpClient.java:434)
>     >     	at cn.jiguang.common.connection.ApacheHttpClient.sendPost(ApacheHttpClient.java:285)
>     >     	at cn.jpush.api.push.PushClient.sendPush(PushClient.java:163)
>     >     	at cn.jpush.api.JPushClient.sendPush(JPushClient.java:193)
>     >     	at com.wybs.bbs.task.service.JPushService.sendNotificationWithAlias(JPushService.java:85)
>     >     	at com.wybs.bbs.task.mq.listener.PushMessageListener.consume(PushMessageListener.java:39)
>     >     	at com.aliyun.openservices.ons.api.impl.rocketmq.ConsumerImpl$MessageListenerImpl.consumeMessage(ConsumerImpl.java:166)
>     >     	at com.aliyun.openservices.shade.com.alibaba.rocketmq.client.impl.consumer.ConsumeMessageConcurrentlyService$ConsumeRequest.run(ConsumeMessageConcurrentlyService.java:417)
>     >     	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
>     >     	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
>     >     	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
>     >     	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
>     >     	at java.lang.Thread.run(Thread.java:748)
>     >     [wybs-bbs-task] 2018-05-29 17:22:07.702 [ConsumeMessageThread_6] DEBUG [com.wybs.bbs.task.service.JPushService:86] - sendNotificationWithAlias() - push all - msgId=65302200359365847, title=你有 2 条回答因违规已被屏蔽, notification= , alias=1768128, payload={"platform":["android","ios"],"audience":{"alias":["1768128"]},"notification":{"ios":{"alert":{"title":"你有 2 条回答因违规已被屏蔽","body":" "},"extras":{"id":"1768128","type":"5"},"badge":"+1","sound":"default"},"android":{"alert":" ","extras":{"id":"1768128","type":"5"},"title":"你有 2 条回答因违规已被屏蔽"}},"options":{"sendno":1234994285,"apns_production":true}}
>     >     [wybs-bbs-task] 2018-05-29 17:22:07.708 [ConsumeMessageThread_5] DEBUG [com.wybs.bbs.task.service.JPushService:86] - sendNotificationWithAlias() - push all - msgId=20266202644947429, title=你对此问题的回答因违规已被屏蔽, notification=初三初四, alias=1768181, payload={"platform":["android","ios"],"audience":{"alias":["1768181"]},"notification":{"ios":{"alert":{"title":"你对此问题的回答因违规已被屏蔽","body":"初三初四"},"extras":{"id":"115","type":"2"},"badge":"+1","sound":"default"},"android":{"alert":"初三初四","extras":{"id":"115","type":"2"},"title":"你对此问题的回答因违规已被屏蔽"}},"options":{"sendno":1960745017,"apns_production":true}}

#16

看日志你是推送了几条消息,其中一条报错找不到目标,[quote=“orz233, post:15, topic:27090”]
Got error response - responseCode:400, responseContent:{“msg_id”: 65302200359439572, “error”: {“message”: “cannot find user by this audience”, “code”: 1011}}
[/quote]

一条消息对应一个msgid 值
如果推送多条消息并不是你的预期,请看代码里面是不是重复调了推送方法