菜鸟教程小白 发表于 2022-12-11 20:45:33

iOS 通知动态操作类别


                                            <p><p>我需要通过有效负载显示推送通知的动态操作。像这样:</p>

<pre><code> {
Platform&#34;: &#34;apns&#34;,
    &#34;Title&#34;:&#34;Booking from API&#34;,
    &#34;Content&#34;: &#34;Hello there&#34;,
    &#34;Category&#34;: &#34;confirmBooking&#34;,
    &#34;Actions&#34;:[
      {
            &#34;ButtonText&#34;: &#34;Confirm&#34;,
            &#34;ActionName&#34;: &#34;confirmBooking&#34;
      },
      {
            &#34;ButtonText&#34;: &#34;Decline&#34;,
            &#34;ActionName&#34;: &#34;declineBooking&#34;
      },
    ]
}
</code></pre>

<p>它的好习惯是什么?到目前为止有可能吗? </p>

<p>目前我正在对类别使用静态配置,并且效果很好:</p>

<pre><code>      var confirm_action = UNNotificationAction.FromIdentifier(&#34;confirm&#34;, &#34;Confirm&#34;, UNNotificationActionOptions.None);
      var decline_action = UNNotificationAction.FromIdentifier(&#34;decline&#34;, &#34;Decline&#34;, UNNotificationActionOptions.None);

      // Create category
      var categoryID = &#34;bookingConfirm&#34;;
      var actions = new UNNotificationAction[] { confirm_action, decline_action };
      var intentIDs = new string[] { };
      var categoryOptions = new UNNotificationCategoryOptions[] { };
      var category = UNNotificationCategory.FromIdentifier(categoryID, actions, intentIDs, UNNotificationCategoryOptions.None);


      var categories = new UNNotificationCategory[] { category };
      UNUserNotificationCenter.Current.SetNotificationCategories(new NSSet&lt;UNNotificationCategory&gt;(categories));
</code></pre>

<p>但不处理任务</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>到目前为止,我认为您无法通过有效负载显示推送通知的动态操作。iOS 系统不支持您这样做。</p>

<p>在 iOS 文档的 <code>UNNotificationAction</code> 部分,它写道:</p>

<blockquote>
<p>Because your app must handle all actions, you must declare the actions
that your app supports <code>at launch time</code>.</p>
</blockquote>

<p>可以引用:</p>

<p> <a href="https://developer.apple.com/documentation/usernotifications/unnotificationaction" rel="noreferrer noopener nofollow">https://developer.apple.com/documentation/usernotifications/unnotificationaction</a>
<a href="https://developer.apple.com/documentation/usernotifications/declaring_your_actionable_notification_types" rel="noreferrer noopener nofollow">https://developer.apple.com/documentation/usernotifications/declaring_your_actionable_notification_types</a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于iOS 通知动态操作类别,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/53048306/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/53048306/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iOS 通知动态操作类别