菜鸟教程小白 发表于 2022-12-11 16:37:58

ios - 带有 sns 主题和 boto3 的静默苹果推送通知


                                            <p><pre><code>topic = sns.Topic(topic_arn)
body = {&#39;aps&#39;: {&#39;content-available&#39;: 1, &#39;sound&#39;: &#39;&#39;}, &#39;update_type&#39;: 2, &#39;update_code&#39;: 44584}
body_json = json.dumps(body, ensure_ascii=False)

message = {&#39;default&#39;: &#39;The default message&#39;,
         &#39;APNS_SANDBOX&#39;: body_json}

MESSAGE_JSON = json.dumps(message, ensure_ascii=False)

response = topic.publish(
    Message=MESSAGE_JSON,
    Subject=&#39;test subject&#39;,
    MessageStructure=&#39;json&#39;
)
</code></pre>

<p>这就是我尝试使用 <code>sns</code> 和 <code>boto3</code> 向主题发布消息的方式。它工作正常,我在我的 <code>iOS</code> 移动设备中收到通知,例如</p>

<pre><code>{
   &#34;aps&#34; =   {
       &#34;alert&#34; = {
                  &#34;default&#34; = &#34;The default message&#34;;
                  &#34;APNS_SANDBOX&#34; = {
                                 &#34;aps&#34; = {
                                          &#34;content-available&#34; = 1;
                                          &#34;sound&#34; = &#34;&#34;
                                    };
                                    &#34;update_type&#34; = 2;
                                    &#34;update_code&#34; = 44584;
                                 }
               }
               }
}
</code></pre>

<p>据我所知,由于我发送的消息带有“警报”标签,即使应用程序不在后台运行,它也会立即显示在通知区域中。</p>

<p>很多链接,建议附加<strong>"content-available": 1</strong>,结果不变。
实际上,我正在寻找一个静默推送通知,以便我可以根据它采取一些行动。为此,我必须收到类似的通知</p>

<pre><code>{
aps =   {
      &#34;content-available&#34; = 1;
      &#34;sound&#34; = &#34;&#34;;
};
&#34;update_code&#34; = 44584;
&#34;update_type&#34; = 2;
}
</code></pre>

<p>为什么即使我包含 <strong>"content-available": 1</strong>,通知中也会出现 <strong>alert</strong> 标签? </p>

<p>任何帮助将不胜感激。<br/>
谢谢</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>这似乎与我从未解决过的相同问题有关:</p>

<p> <a href="https://gist.github.com/tmarshall/6149ed2475f964cda3f5" rel="noreferrer noopener nofollow">Silent push</a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 带有 sns 主题和 boto3 的静默苹果推送通知,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/37561939/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/37561939/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 带有 sns 主题和 boto3 的静默苹果推送通知