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

ios - ANCS : what is the concept of PositiveAction?


                                            <p><p>我正在尝试使用 Apple 通知中心服务在蓝牙外围设备和 iOS 设备之间进行交互。
在 <a href="https://developer.apple.com/library/ios/documentation/CoreBluetooth/Reference/AppleNotificationCenterServiceSpecification/Specification/Specification.html#//apple_ref/doc/uid/TP40013460-CH1-SW61" rel="noreferrer noopener nofollow">documentation</a> Apple 提到了 2 个通知 Action :EventFlagPositiveAction 和 EventFlagNegativeAction……</p>

<p>到目前为止,<em>Negative</em> 部分起作用:一旦通知被传输到外围设备,后一个可以触发否定操作,从而导致通知被解除。</p>

<p>但我无法触发力量的<em>积极</em>方面...我的通知有一个操作按钮,我希望此按钮被视为积极行动...但我不知道它是如何工作的:它是隐式的吗?所有 Action 都有 <em>positive</em> 标志吗?还是我应该做点什么让它被认为是<em>积极的</em>?</p>

<p>这更多是关于 ACNS 的概念性问题,但为了提供信息,下面是我正在使用的代码:</p>

<p>第一次在 AppDelegate 中注册本地通知:</p>

<pre><code>    let notificationTypes = UIUserNotificationType.Alert.union(UIUserNotificationType.Sound).union(UIUserNotificationType.Badge)

    let launchAction = UIMutableUserNotificationAction()
    launchAction.identifier = &#34;LAUNCH_ACTION&#34;
    launchAction.title = &#34;OK&#34;
    launchAction.activationMode = UIUserNotificationActivationMode.Foreground
    launchAction.destructive = false
    /* this is this UIMutableUserNotificationAction that I want to trigger from my external device, and should be considered as the famous positive action I am looking for */

    let notificationCategory = UIMutableUserNotificationCategory()

    notificationCategory.identifier = &#34;LAUNCH_NOTIFICATION&#34;
    notificationCategory.setActions(, forContext: .Minimal)
    application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: notificationTypes, categories: NSSet(array:) as? Set&lt;UIUserNotificationCategory&gt;))
</code></pre>

<p>第二,稍后创建通知</p>

<pre><code>    let localNotification:UILocalNotification = UILocalNotification()
    localNotification.alertAction = &#34;Hello&#34;
    localNotification.alertBody = &#34;World&#34;
    localNotification.fireDate = NSDate(timeIntervalSinceNow: 5)
    localNotification.soundName = UILocalNotificationDefaultSoundName
    localNotification.hasAction = true
    localNotification.category = &#34;LAUNCH_NOTIFICATION&#34;
    UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>好的,那么我已经从 Apple 开发人员技术支持那里得到了我的问题的答案。
在这里发布,希望这对其他人有帮助:</p>

<blockquote>
<p>the first thing to understand is that “Positive actions are only wired up for telephony related notifications (incoming call, missed call, and voicemail).There is currently no way to pass through the positive action for an app alert.</p>
</blockquote>

<p>现在事情更容易理解了……</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - ANCS : what is the concept of PositiveAction?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/37795587/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/37795587/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - ANCS : what is the concept of PositiveAction?