如果测试应用程序也变得活跃从UILocalNotification [英] Test if app did become active from a UILocalNotification
问题描述
有没有办法知道,如果没有应用程序从本地通知变得活跃?
Is there a way to know if the application did become active from a local notification?
我知道有一种方式来测试,如果应用程序是的发起从本地通知提醒;但如果它只是坐在那里背景,收到通知?
I know there is a way to test if the application was launched from a local notification alert; but if it just was sitting out there the background, and received a notification?
我需要运行不同的code,当应用程序变为活动:
I need to run different code, when the app has become active:
- 从本地通知。
- 就变得活跃:)
有没有办法做到这一点?
Is there a way to do it?
推荐答案
恐怕Sylter不正确。当一个应用程序进入与背景的前景的 的,或者由用户直接操作或由用户响应于 UILocalNotification
,它不会触发 applicationDidFinishLaunchingWithOptions
。它,然而,叫 applicationWillEnterForeground
和 applicationDidBecomeActive
。这可以用一对夫妇的 NSLogs
进行验证。
I'm afraid Sylter is incorrect. When an app enters the foreground from the background, either by a direct user action or by a user response to a UILocalNotification
, it does not trigger applicationDidFinishLaunchingWithOptions
. It does, however, call applicationWillEnterForeground
and applicationDidBecomeActive
. This can be verified with a couple of NSLogs
.
因此,问题仍然是:如果某个应用从背景进入前景,也没有办法来发现如果该应用是响应于用户的响应于 UILocalNotification 进入前景code>,或者如果它仅仅进入前景。除...
So, the problem remains: if an app is entering the foreground from the background, there is no way to discover if the app is entering the foreground in response to a user's response to a UILocalNotification
, or if it is merely entering the foreground. Except...
在应用程序已进入前景,它将接收方法应用程序:DidReceiveLocalNotification
:如果应用进入前台响应 UILocalNotification
。
Once the app has entered the foreground, it will receive the method application:DidReceiveLocalNotification
: if the app entered the foreground in response to a UILocalNotification
.
问题是,应用程序中所做的任何用户界面的变化:DidReceiveLocalNotification:收到的UILocalNotification响应
方法出现的之后的应用早已进入前台,为用户创造一个令人不安的体验。
The problem is that any UI changes made within the application:DidReceiveLocalNotification:
method in response to receiving the UILocalNotification occur after the app has already entered the foreground, creating a disturbing experience for the user.
有没有人找到一个解决方案?
Has anyone found a solution?
这篇关于如果测试应用程序也变得活跃从UILocalNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!