首页 > 编程知识 正文

adblock怎么用ios进p站,javapp

时间:2023-05-06 17:27:59 阅读:24527 作者:2308

提示:写完文章后,目录可以自动生成。 如何生成可以引用右侧的帮助文档

文章目录一,Pushy是什么? 二、步骤1 .使用1.APNS推送进程2设置相关配置1.p12证书准备初始化APNSClient请求3 .工具类示例说明

一、Pushy是什么? pushy框架介绍

Pushy是用于发送APN(IOs、MacOS、Safari )推送通知的Java库。 由Turo的工程师制作并维护。

Pushy使用Apple基于HTTP/2的APN协议发送推送通知,支持TLS和基于令牌的认证。 与其他推送通知库不同,它侧重于全面的文档记录、异步操作和工业规模操作设计。 使用Pushy,您可以通过维护到APN网关的多个并发连接,轻松高效地向大量不同的APP应用程序“主题”发送大量通知。

我相信Pushy已经是从Java APP应用程序发送APN推送通知的最佳工具。 我们还希望通过错误报告和拉式请求帮助我们更好地实现这一点。 如果您对使用Pushy有任何疑问,请加入Pushy邮件列表或查看wiki。 谢谢你!

上面摘录在git文档中

源地址: pushy源地址

二、步骤1.APNS推送流程1 .在1.IOS app端根据证书向APNS注册获取设备令牌并向服务端报告

2 .服务端根据令牌发送通知请求

异步获取APNS服务器的反馈结果信息

代码如下所示。

# gradlecom.eatthepath : pushy :0.15.02配置相关配置1.p12证书准备相关证书ios开发导出文件证书必须位于开发环境证书中。 然后,要初始化apnsclient,必须根据环境证书初始化请求地址(PS :后续代码说明)2.初始化apnsclient

APNS请求对象的publicclassapnsconnect { privatestaticapnsclientapnsclient=null; publicstaticapnsclientgetapnsconnect () if ) APNsclient==null ) try(/设置环境inputstream inputstream=pushfcmapnsproperoperoperarararam fileutils.copyinputstreamtofile (inputstream,bathFile ); //设置信息包括服务器地址apnsclientbuilder.development _ apns _ host开发环境地址//apnsclientbuilder.production _ apns _ host : apnsclient.production _ apns _ host : APN sclient==setClientCredentials包含与证书文件证书相对应的文件密码。 setclientcredentials(bathfile,pushfcmapnsproperties.iosp 12 password ).SOSP12 }catch(exceptione ) log.error ) iror ' ); e .打印堆栈跟踪(; } }返回APN客户端; }3.工具类示例@ sl F4 jpublicclassapnspush { publicstaticvoidpush (liststringdevicetokens,String alertTitle,String alertBody,字符串警报主体)

perty, Map<String, NotificationPushDevice> badgeMap) { long startTime = System.currentTimeMillis(); ApnsClient apnsClient = APNSConnect.getAPNSConnect(); long total=deviceTokens.size(); long startPushTime = System.currentTimeMillis(); for (String deviceToken : deviceTokens) { ApnsPayloadBuilder payloadBuilder =new SimpleApnsPayloadBuilder(); if(alertBody!=null) { payloadBuilder.setAlertBody(alertBody); } if(alertTitle !=null){ payloadBuilder.setAlertTitle(alertTitle); } //如果badge小于0,则不推送这个右上角的角标,主要用于消息盒子新增或者已读时,更新此状态 payloadBuilder.setBadgeNumber(1); //将所有的附加自定义参数全部放进去 if(customProperty!=null) { for(Map.Entry<String, String> map:customProperty.entrySet()) { payloadBuilder.addCustomProperty(map.getKey(),map.getValue()); } } payloadBuilder.setContentAvailable(contentAvailable); String payload = payloadBuilder.build(); final String token = TokenUtil.sanitizeTokenString(deviceToken); SimpleApnsPushNotification pushNotification = new SimpleApnsPushNotification(token, PushFcmApnsProperties.iosTopic, payload,Instant.now().plus(Duration.ofDays(1)), DeliveryPriority.IMMEDIATE, PushType.ALERT); //发送消息回复返回值 final PushNotificationFuture<SimpleApnsPushNotification, PushNotificationResponse<SimpleApnsPushNotification>> sendNotificationFuture = apnsClient.sendNotification(pushNotification); //监听--用以提高效率 sendNotificationFuture.whenComplete((pushNotificationResponse, cause) -> { if (pushNotificationResponse != null) { // Handle the push notification response as before from here. if (pushNotificationResponse.isAccepted()) { log.info("Push notification accepted by APNs gateway."); } else { log.error("Notification rejected by the APNs gateway: " + pushNotificationResponse.getRejectionReason()); pushNotificationResponse.getTokenInvalidationTimestamp().ifPresent(timestamp -> { log.error("t…and the token is invalid as of " + timestamp); }); } } else { // Something went wrong when trying to send the notification to the // APNs server. Note that this is distinct from a rejection from // the server, and indicates that something went wrong when actually // sending the notification or waiting for a reply. cause.printStackTrace(); } }); } long endPushTime = System.currentTimeMillis(); log.info("test pushMessage success. [共推送" + total + "个],time= " + (endPushTime - startTime) ); } 小记

接入流程没任何难度,看pushy 对应的wiki 很清晰,主要是app 联调过程中需要注意各个环境的细节,报错错误码没有对应的文档 ,这个比较麻烦,大部分错误都是证书过期 或者对应的环境有问题 token 不对等情况

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。