首页 > 解决方案 > AWS CLI SNS 向我的 iOS 应用程序推送通知有效,但如何播放不同的声音或更改徽章编号?

问题描述

我正在使用 Amazon Web Service 命令行界面使用以下命令向我的 iOS 应用程序发送推送通知:

aws sns publish --target-arn \"arn:aws:sns:us-east-1:545678945607:endpoint/APNS_SANDBOX/MyApp/lk4ggss56-2F29-3r55-6Qw2-dsd4sad4s5a\" --message \"hello!\" 

这很好用,但是否也可以传递信息以播放非默认声音或使用 AWS CLI 更改应用程序的徽章编号?

当直接向 Apple 的 APNs 发送消息时,您可以发布与此类似的 json 块来更改播放的声音或徽章编号:

{
  "aps" : {
    "alert" : {
      "title" : "testMessage",
      "body" : "Hi!"
    },
    "sound" : "0546.aiff",
    "badge": "100"
  }
}

这对我来说是全新的,任何帮助将不胜感激!谢谢!

解决了

更新:对我有用的解决方案:

使用了这个命令:

aws sns publish --target-arn \"arn:aws:sns:us-east-1:545678945607:endpoint/APNS_SANDBOX/MyApp/lk4ggss56-2F29-3r55-6Qw2-dsd4sad4s5a\" --message-structure \"json\"  --message file://aps.json

名为“aps.json”的文件的内容是:

{"default":"This is the default Message","APNS_SANDBOX":"{ \"aps\" : { \"alert\" : \"New push notification.\", \"badge\" : 9,\"sound\" :\"0546.aiff\"}}"}

它设置了徽章编号,并使用了我的应用程序中包含的自定义声音。

标签: iosamazon-web-servicespush-notificationcommand-line-interface

解决方案


对我有用的解决方案:

使用了这个命令:

aws sns publish --target-arn \"arn:aws:sns:us-east-1:545678945607:endpoint/APNS_SANDBOX/MyApp/lk4ggss56-2F29-3r55-6Qw2-dsd4sad4s5a\" --message-structure \"json\"  --message file://aps.json

名为“aps.json”的文件的内容是:

{"default":"This is the default Message","APNS_SANDBOX":"{ \"aps\" : { \"alert\" : \"New push notification.\", \"badge\" : 9,\"sound\" :\"0546.aiff\"}}"}

其中设置了徽章编号,并使用了我的应用程序中包含的自定义声音。

视窗:

aws sns publish --topic-arn "arn:aws:sns:eu-west-2:123412341234:some-topic" --message-structure json --message '{\"default\":\"This is the default Message\",\"test\": \"value\"}'

推荐阅读