gpt4 book ai didi

iphone - 检测应用程序是否由于 UILocalNotification 获得焦点

转载 作者:行者123 更新时间:2023-12-03 18:37:15 25 4
gpt4 key购买 nike

我正在制作一个应用程序,用于跟踪一些按照用户定义的时间间隔重复的提醒。

我已经做到了,当警报显示时,操作标题显示“更新”。当您单击此按钮时,应用程序将打开,在这里我想创建下一个提醒,但问题是我不知道应用程序打开是因为点击了通知按钮,还是在应用程序运行时触发了通知。

有人有什么想法吗?

最佳答案

执行此操作的“正确”方法是在委托(delegate)的 application:didReceiveRemoteNotification: 方法中检查 NSApplication 的 applicationState 属性。

来自documentation用于处理本地通知:

iOS Note: In iOS, you can determine whether an application is launched as a result of the user tapping the action button or whether the notification was delivered to the already-running application by examining the application state. In the delegate’s implementation of the application:didReceiveRemoteNotification: or application:didReceiveLocalNotification: method, get the value of the applicationState property and evaluate it. If the value is UIApplicationStateInactive, the user tapped the action button; if the value is UIApplicationStateActive, the application was frontmost when it received the notification.

这与您使用 applicationWillEnterForeground 和 applicationDidBecomeActive 中设置的标志的解决方案类似,但具有系统支持。

关于iphone - 检测应用程序是否由于 UILocalNotification 获得焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7637158/

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