如果测试应用程序也变得活跃从UILocalNotification [英] Test if app did become active from a UILocalNotification

查看:136
本文介绍了如果测试应用程序也变得活跃从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:


  1. 从本地通知。

  2. 就变得活跃:)

有没有办法做到这一点?

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 ,或者如果它仅仅进入前景。除...

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

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