测试应用程序是否确实从 UILocalNotification 变为活动状态 [英] Test if app did become active from a UILocalNotification

查看:19
本文介绍了测试应用程序是否确实从 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?

当应用激活时,我需要运行不同的代码:

I need to run different code, when the app has become active:

  1. 来自本地通知.
  2. 刚刚开始活跃:)

有办法吗?

推荐答案

恐怕 Sylter 不正确.当应用程序从后台进入前台时,无论是通过直接用户操作还是通过用户对 UILocalNotification 的响应,它都不会触发 applicationDidFinishLaunchingWithOptions.但是,它确实调用了 applicationWillEnterForegroundapplicationDidBecomeActive.这可以通过几个 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 的响应而进入前台,或者如果它只是进入前台.除了...

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...

一旦应用进入前台,它会收到application: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.

问题是在 application:DidReceiveLocalNotification: 方法中为响应接收 UILocalNotification 而进行的任何 UI 更改发生在 应用已经进入前台之后,从而创建了一个给用户带来不安的体验.

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆