gpt4 book ai didi

ios - 检测应用程序是否是从通知中心或应用程序图标中点击启动的,设置键内容可用=1

转载 作者:行者123 更新时间:2023-11-28 06:27:51 25 4
gpt4 key购买 nike

我试过这个:Detect if the app was launched/opened from a push notification

但不同的是,我设置了content-available = 1键,这意味着didReceiveRemoteNotification事件不仅在通知中播放时一直执行中心。如何区分通知中心或图标应用何时被触发?

最佳答案

我已经找到解决方案,该帖子可能对其他人有用。在 didReceiveRemoteNotification fetchCompletionHandler 中,将变量 timeReceiveRemoteNotification = NSDate () 设置为收到通知的日期。在 applicationDidBecomeActive 中,我检查当前日期与执行 didReceiveRemoteNotification 事件之间耗时是否小于 1 秒。因为如果应用程序是从通知中心启动的,第一个执行的方法是 didReceiveRemoteNotification 然后是 applicationDidBecomeActive 如果它是从应用程序图标启动的,则执行的事件只是applicationDidBecomeActive 和因此变量 timeReceiveRemoteNotification 保持通知接收日期的分配值,这可能超过一秒。在 applicationDidBecomeActive 中,代码是:

LaunchIconApp = true
        println (NSDate().TimeIntervalSinceDate (timeReceiveRemoteNotification))
        if(launchIconApp && launchNotification && NSDate().TimeIntervalSinceDate (timeReceiveRemoteNotification) <1)
        {
            println("Comes from the notification center")
            LaunchNotification = false
        } Else {
            println("Comes from the app icon")
        }

关于ios - 检测应用程序是否是从通知中心或应用程序图标中点击启动的,设置键内容可用=1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41293134/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com