mis*_*ena 7 push-notification amazon-web-services apple-push-notifications amazon-sns javaapns
我的目标最终目标是通过SNS向iOS应用发送推送通知.我正在逐步完成本教程:http://docs.aws.amazon.com/sns/latest/dg/mobile-push-apns.html.
我已在我的AWS凭据中添加,并添加了相应的apns凭据,用于我的应用程序的开发密钥,证书,私钥和当前推送令牌.当我运行教程时,我得到:
Exception in thread "main" java.lang.NullPointerException
at com.amazonaws.sns.samples.tools.AmazonSNSClientWrapper.getValidNotificationAttributes(AmazonSNSClientWrapper.java:162)
at com.amazonaws.sns.samples.tools.AmazonSNSClientWrapper.publish(AmazonSNSClientWrapper.java:80)
at com.amazonaws.sns.samples.tools.AmazonSNSClientWrapper.demoNotification(AmazonSNSClientWrapper.java:131)
at com.amazonaws.sns.samples.mobilepush.SNSMobilePush.demoAppleSandboxAppNotification(SNSMobilePush.java:438)
at com.amazonaws.sns.samples.mobilepush.SNSMobilePush.main(SNSMobilePush.java:68)
Run Code Online (Sandbox Code Playgroud)
在SNSMobilePush.java的顶部有一个名为attributesMap的Map.对于密钥Platform.APNS和Platform.APNS_SANDBOX,它最初的值设置为null.在代码期间,这些值永远不会改变,并且负责导致空指针异常.本教程未指示更改这些值.
我没有做任何超出教程说明的内容.
我知道我的凭据是正确的,因为我通过Amazon Management Console使用这些相同的凭据向我的iOS应用程序发送消息.
任何人都可以表示
更新我在null检查中添加了getValidNotificationAttributes(),现在我可以使用本教程使用sns和apns发送推送通知.
我通过向 AmazonSNSClientWrapper 类中的 getValidNotificationAttributes() 添加空检查来使教程正常运行。我确信这是使用 Platform APNS_SANDBOX 和 APNS(可能还有 ADM 和 GCM)时暴露的代码缺陷。
public static Map<String, MessageAttributeValue> getValidNotificationAttributes(
Map<String, MessageAttributeValue> notificationAttributes) {
if (notificationAttributes != null) {
Map<String, MessageAttributeValue> validAttributes = new HashMap<String, MessageAttributeValue>();
for (Map.Entry<String, MessageAttributeValue> entry : notificationAttributes.entrySet()) {
if (!StringUtils.isBlank(entry.getValue().getStringValue())) {
validAttributes.put(entry.getKey(), entry.getValue());
}
}
return validAttributes;
} else {
return new HashMap<String, MessageAttributeValue>();
}
}
Run Code Online (Sandbox Code Playgroud)
我希望这对正在学习本在线教程的其他人有所帮助。