iOS应用程序生命周期4 / 3GS / iPad与2G / 3G [英] iOS app lifecycle 4/3GS/iPad vs 2G/3G

查看:107
本文介绍了iOS应用程序生命周期4 / 3GS / iPad与2G / 3G的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读Apple的文档关于应用程序生命周期,并进行了一些测试,以确定不同设备上的应用程序生命周期。 (所有正在运行的iOS 4.x除了2G)



我测试了多任务功能设备与不支持此功能的设备:



iPhone 2G / 3G应用程序生命周期:

 (START)
- didFinishLunchingWithOptions
- applicationDidBecomeActive

(首页已售出)
- applicationDidEnterBackground
- appWillTerminate

iPad / iPhone 4应用程序生命周期:

 (START)
- didFinishLunchingWithOptions
- applicationDidBecomeActive

(主页新闻)
- appWillResignActive
- appDidEnterBackGround

(任务栏中的RESART应用程序)
- appWillEnterForeGround
- appDidBecomeActive

我试图从任务栏中杀死应用程序但是调试器收到了SIGKILL!当你以这种方式杀死和app时会发生什么?



appWillTerminate什么时候调用多任务设备?我的结果是否正确?



编辑:



引用苹果公司关于appWillTerminate的文档:


对于支持后台执行的应用程序,当用户退出应用程序时通常不会调用此方法,因为在这种情况下应用程序只是移动到后台。但是,可以在应用程序在后台运行(未暂停)并且系统因某种原因需要终止它的情况下调用此方法。


通常不叫是什么意思。 系统需要终止它..意味着将调用方法 appWillTerminate

解决方案

我认为你是对的。当您从任务栏中终止应用程序时(或者当您的设备内存不足并且操作系统为您杀死应用程序时),它只会发送SIGKIL信号。如你所知,它从不调用任何回调。



根据文档


对于应用程序支持
后台执行,这个方法是
,当用户
退出应用程序时通常不会调用,因为在这种情况下
应用程序只是移动到
后台。但是,这个
方法可以在
的情况下调用,其中应用程序在
后台运行(未暂停),
系统需要终止它
原因。


因此,iOS 可以调用 applicationWillTerminate:方法,但可能不会。 (我从未见过它。)



如果你想在你的应用程序被杀之前保存任何状态,你需要在它进入后台时这样做。 / p>

I've read the Apple's documentation about application lifecycle and made some tests to figure out what is the applications life cycle on different devices. (All running iOS 4.x except the 2G)

I've tested "multitasking" capable devices vs some that do not support this feature :

iPhone 2G/3G app lifecycle :

(START)
- didFinishLunchingWithOptions
- applicationDidBecomeActive

(HOME PRESSED)
- applicationDidEnterBackground
- appWillTerminate

iPad / iPhone 4 app lifecycle:

(START)
- didFinishLunchingWithOptions
- applicationDidBecomeActive

(HOME PRESSED)
- appWillResignActive
- appDidEnterBackGround

(RESART app in the "Taskbar")
- appWillEnterForeGround
- appDidBecomeActive

I've tried to kill the App from the "taskbar" but the debugger received a SIGKILL ! What happens when you kill and app in that way ?

When is appWillTerminate called on the "multitasking" capable device ? Are my results correct ?

EDIT:

Quote from apple's doc about appWillTerminate :

For applications that support background execution, this method is generally not called when the user quits the application because the application simply moves to the background in that case. However, this method may be called in situations where the application is running in the background (not suspended) and the system needs to terminate it for some reason.

What do they mean by "generally not called". " the system needs to terminate it.." means that the method appWillTerminate will be invoked ?

解决方案

I think you're right. When you kill an app from the taskbar (or when your device is running low on memory and the OS kills the app for you), it just sends a SIGKIL signal. As you note, it never calls any of the callbacks.

According to the documentation:

For applications that support background execution, this method is generally not called when the user quits the application because the application simply moves to the background in that case. However, this method may be called in situations where the application is running in the background (not suspended) and the system needs to terminate it for some reason.

So, iOS can call the applicationWillTerminate: method but probably won't. (I've never seen it.)

If you want to save any state before your app is killed, you need to do it as it goes into the background.

这篇关于iOS应用程序生命周期4 / 3GS / iPad与2G / 3G的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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