【问题标题】:APNS: Receive non silent notifications if app is not running?APNS:如果应用程序未运行,是否接收非静默通知?
【发布时间】:2017-10-05 09:15:45
【问题描述】:

正如我在 APNS 文档中看到的那样,如果应用程序未运行,静默通知将在 didreceiveremotenotification 中处理,但它们的优先级较低。所以有时我的 iOS 应用程序不会收到静默通知。

如果应用未运行(不在前台,不在后台),iOS 是否会显示非静默通知?非静默通知会触发didreceiveremotenotification吗?

【问题讨论】:

    标签: ios xamarin xamarin.ios apple-push-notifications apns-sharp


    【解决方案1】:

    对于非静默通知,

    如果应用处于activeinactive 状态,将触发didreceiveremotenotification。不是terminatedsuspended 状态。 在terminatedsuspended 状态的情况下,当用户点击通知应用程序时,将通过调用didFinishLaunchingWithOptionslaunchingOptions 启动有效载荷为Dictionary

    如果您提供UNNotificationServiceExtension,则iOS 将在收到通知时调用didReceive(_:withContentHandler:),您可以使用它来自定义远程通知的内容,然后再将其发送给用户。 阅读:https://developer.apple.com/documentation/usernotifications/unnotificationserviceextension

    如果您提供UNNotificationContentExtension,那么iOS 将在收到通知时调用didReceive,您可以使用它自定义加载通知内容。

    阅读:https://developer.apple.com/documentation/usernotificationsui/unnotificationcontentextension

    附注:

    普通通知不能用作静默通知的替代方案/解决方法,因为您不能在应用程序终止状态下使用静默通知。

    静默通知旨在将客户端应用程序与服务器上可用的更新内容同步。因为这可以在没有显式用户交互的情况下完成,所以可以使用静默通知。

    无声通知必须包含content-available 键,并且不得包含警报、声音或徽章键。 阅读:https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html

    在正常通知的情况下,除非手机上的用户设置如此说明,否则无法隐藏通知横幅/警报/声音。

    【讨论】:

    • 正常通知会一直显示,如果应用程序处于暂停或终止状态?
    • Yes buddy :) 应用程序状态只会修改通知如何传递给您的应用程序,正如我上面解释的那样。通知将始终根据用户的通知设备设置(如警报或横幅)显示 无法阻止它以编程方式显示给用户
    猜你喜欢
    • 1970-01-01
    • 2017-12-08
    • 2021-05-01
    • 1970-01-01
    • 2016-09-30
    • 2018-04-21
    • 1970-01-01
    • 1970-01-01
    • 2012-08-17
    相关资源
    最近更新 更多