Understanding iOS 4 Backgrounding and Delegate Messaging

国央企创新负责人如何通过平台实现科研成果的快速识别与转化?.docx 科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。 立即下载

UPDATE: Added handleOpenURL to the flow charts. Added UIApplicationExitsOnSuspend. Untangled some lines.

UPDATE: renamed deprecated handleOpenURL to newer name.

Now that we all are moving our source code gradually to iOS 4 I had to pause and think a bit about where to move which code. A problem that I’m facing frequently when updating a project is that the didFinishLaunching is only called if the app really launches.

That poses a bit of a challenge if you are used to doing things like refreshing images or other files off the internet. An app that is resumed from standby does no longer go through this delegate method. So an app that would always show fresh content upon launch before 4.0 multitasking would no longer load any new content as soon as you build it for 4.0. That’s actually one of the main reasons why I have not yet had time to update MyAppSales to 4.0.

To gain the possibility for “fast app switching” you actually don’t need to do anything. All apps automatically support it because they no longer get terminated if the user pushes the Home button. They get put into a sleep mode while the iPhone still has enough memory for everything else. It’s only if RAM runs out that the OS starts killing apps. There is begins with the ones that have the most memory reserved.

I grabbed the free trial of Omnigraffle and the Non-techie Process Flowchart Stencils by gfraser. Then I researched when all these various delegate methods of UIApplication are being called and drew charts to illustrate the flow.

By inhaling first how it was before multitasking and then upgrading your mental process to backgrounding we can begin to fully appreciate how it all fits together.

Get quality app translation from Apple. We understand development.

 

The World Before Multitasking

The first thing that I learned from this is that applicationDidBecomeActive: is being called right after application:didFinishLaunchingWithOptions:. So even before 4.0 it would have been smart to put there any kind of code that you want executed whenever the app becomes active, be it after app start or upon rejecting a phone call.

Not shown on this diagram is the situation that your app is eating up all the system memory and ignores both the level 1 and level 2 memory warnings. In that case the OS will also terminate your app without totally unscrupulous.

The mechanism with WillResignActive and DidBecomeActive is sort of the Backgrounding Lite that has always been there. This occurs whenever some other thing is displayed in front of your app. This could be the UI to accept a phone call or something as benign as the synching screen.

Multitasking ON

Adding multitasking to this flow chart makes it about twice as complex. I probably spent an hour trying to fit it all together with no crossing lines. Another thing that I noticed while doing this is that applicationWillResignActive: is the only delegate method that I could not optimize into a single box, because one use is to show that the app has been interrupted, the other is to the path into the background.

An app built with 3.2 will still go through a short background stage where applicationDidEnterBackground: is called. but then it will be terminated as usual. If the same app is built against a 4.x SDK then it will not go straight from background to being terminated. Instead it will stick around and so will be the debugger. As soon as you tap the app icon again or choose it from the app switcher it is first informed that applicationWillEnterForeground and then applicationDidBecomeActive.

An app that is suspended but still in RAM might be terminated by the OS if memory runs low. But after entering the background there is no longer any delegate method being called, instead the app will receive a KILL signal. This occurs also if the user long-presses the app icon in app switcher and then removes the app from there with the removal button.

Accepting a phone call no longer terminates your app but will send it into the appropriate background mode. Within the background box you see two purple states that the app can be in. All apps are suspended in RAM per default. You might want to slim down your memory footprint to make your app a less likely target for killing if the system runs low on memory.

Only apps that actually require background processing continue to be executing. This requirement is either set in info.plist or by telling the OS that you have a task to complete, like for example a file upload.

The following kinds of activities get to run in true multi tasking behind the foreground app with lesser CPU priority.

  • playing music: “App plays audio”
  • geo location: “App registers for location updates”
  • VOIP: “App provides Voice over IP services”

If your app does one of these things then adding the key to info.plist is all it takes. But be aware that as soon as your app stops doing what it stated it would be doing the OS again will send it to sleep, only to be awakend by another gentle tap by the user.

In background mode you’re advised to stop updating the UI. Especially with OpenGL Apple is really strict. If you app as much as touches OpenGL while in background the app gets killed right away.

There are only two scenarios left where your app’s applicationWillTerminate: will actually be called: if it’s build with an SDK of less than version 4.0 or if you chose to opt out of backgrounding by adding the UIApplicationExitsOnSuspend key to your info.plist.

So, let’s ask the question we’ve been doing all this fuss for: Where should you now put your code to initialize, update or save changes? applicationWillTerminate not being called in the majority of cases makes it a rather bad candidate to save user defaults or data.

Looking at the chart I see applicationDidEnterBackground as the ideal candidate delegate method for saving state. This is also the last method to be called before a regular 4.0 app gets put to sleep and before a possible kill.

For updating data from the web the case is not as clear. You would not want to reload every time the user comes back to your app. Possible applicationDidBecomeActive: is a good place, provided that you only reload data if sufficient time has passed to be able to assume that something new is available.

Only the first loading of data can stay in application:didFinishLaunchingWithOptions: since every call  applicationDidBecomeActive: most likely has the data already loaded previously.

Conclusion

Adding fast app switching and multitasking support is quite easy since for the most part you don’t need to do anything. But you WILL have to review the contents of your app delegate methods to see which code has to be moved into one of the other delegate methods now. Clean out applicationWillTerminate: and have a close look at application:didFinishLaunchingWithOptions: to check if you have something in there that needs to be done every time the app becomes active.

These charts come from some experimentation that I did and what I remembered from the WWDC 2010 session videos on multitasking. Potentially there are mistakes or more surprises hidden in there. Please let me know if you find any.

Here’s the chart in PDF format in case you want to print it out and frame it.


http://www.cocoanetics.com/2010/07/understanding-ios-4-backgrounding-and-delegate-messaging/

PotPlayer自用皮肤 自用 PotPlayer 皮肤,仅微调了字体大小与颜色,是按个人习惯调整,未做适配性调整。 立即下载

相关推荐

别再死记硬背了!用TwinCAT 3手把手教你配置EtherCAT伺服驱动的PDO映射(DS402协议)

本文详细介绍了如何使用TwinCAT 3配置EtherCAT伺服驱动的PDO映射(DS402协议),涵盖环境准备、设备扫描、PDO映射实战及高级技巧。通过具体操作步骤和常见问题排查,帮助工程师快速掌握EtherCAT通信配置,提升运动控制系统的效率和稳定性。

weixin_29185493的博客 322

【转载】Understanding iOS 4 Backgrounding and Delegate Messaging

转载自:http://www.cocoanetics.com/2010/07/understanding-ios-4-backgrounding-and-delegate-messaging/ Understanding iOS 4 Backgrounding and Delegate Messaging Jul 04, 2010 UPDATE: Added han...

weixin_30377461的博客 106

EDA开源仿真工具verilator入门4:访问函数介绍

访问函数(Visitor Function)是verilator算法实现的主要工作方式之一,本节将介绍一下访问函数。

fangfanglovezhou的博客 1075

iOS 多语言本地化教程,VS Code KXApp 编辑 String Catalog .xcstrings

做 iOS 多语言本地化总要在 VS Code 和 Xcode 之间来回切?这篇讲用 KXApp(快蝎)在 VS Code 里直接编辑 String Catalog(.xcstrings):双击打开和 Xcode 一样的表格,`.xcstrings` 与老的 `.strings`、`.stringsdict` 同表编辑,加语言同步登记到工程、从源码扫描同步新 key,复数、设备变体和变量占位都在表里处理,改源语言文本后已有翻译自动标需复核。文件仍是标准格式,回 Xcode 打开一致。

2501_91592143的博客 171

IAR安装成功的关键:STM32设备支持文件导入方法

IAR安装常卡在设备支持缺失这一步——尤其对STM32新手,没导入对应芯片包,编译直接报错。实测发现,必须通过IAR的Tools→Options→IDE→Configuration→Device Support手动加载STM32设备支持文件,否则新建工程时连芯片型号都选不到。IAR安装是否顺利,往往就差这一步。

weixin_42527589的博客 680

DIY电子管耳放实战:12AU7+6V6GT组合的电路设计与调试心得

本文详细分享了DIY电子管耳放的实战经验,重点解析了12AU7与6V6GT经典组合的电路设计、元件选型与调试过程。内容涵盖从核心架构设计、关键元件(如输出变压器、耦合电容)的科学选型,到静态工作点设置、负反馈引入及常见噪声问题的排查,旨在帮助音响DIY爱好者和电子管放大器初学者成功打造一台低失真、高信噪比且富有“胆味”的耳机放大器,享受动手制作的乐趣与温暖音质。

weixin_29230805的博客 552

安卓IOS打包证书

.p12 、 .mobileprovision 、 keystore 相关证书申请

weixin_58431406的博客 285

产品经理-面试题目--持续更新

答:面试官,你好,我叫XXX,来自于XXXX,我系统的学习过软件开发,也主动的积累了不少产品方面的实战经验,在学习期间,我自己独立的完成了2个深度项目,一个是仿抖音的短视频APP全流程设计,另外一个是电商后台系统的模块,通过这些项目,我不仅熟练使用Axure等工具做出高保真原型图和清晰的产品框架,也形成了数据驱动和用户优先的思维习惯,另外,我也注重拓展自己的能力边界,拿到了CAIE人工智能证书,我希望能把AI能力融入到产品场景,提升体验和效率,我非常喜欢产品工作带来的创造性和逻辑性,希望有机会加入贵公司。

m0_63966958的博客 957

React Native项目开发(iOS侧为例)

本文基于React Native 0.71+,通过npx react-native init初始化项目后,详细讲解如何使用TypeScript搭建两个页面:入口页(Entrance.tsx)和我的页面(Profile.tsx)。重点介绍了配置tsconfig.json、初始化TypeScript环境、集成React Navigation实现页面跳转,并通过创建共享类型文件(navigation.ts)实现路由类型安全。文章还涵盖依赖安装、iOS构建问题排查、目录结构规范及常见错误解决方案。

D_xw_的博客 261

TGRS 2026 即插即用 | 注意力篇 | SCFM:双向交叉显著性引导注意力,高层语义与低层细节的双向互补!

本文介绍了MPCNet中的语义引导交叉注意力融合模块(SCFM),该模块通过双向交叉显著性引导机制实现跨尺度特征融合。SCFM创新性地结合了高层语义和低层细节的互补信息,通过轻量局部空间注意力预增强和坐标注意力全局融合引导,显著提升了红外小目标检测的精度。实验表明,SCFM在多个数据集上达到SOTA性能,同时保持轻量高效的计算特性,支持端侧设备部署。 SCFM的核心贡献包括: 双向交叉显著性引导机制,实现语义与细节的互补融合 轻量局部空间注意力预增强模块,计算量仅为传统方法的1/10 坐标注意力全局融合引导

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 145

【2022网易雷火】游戏研发笔试-AC代码及题目分享

3个小时,4道题目,雷火的题目不在于难,更在于对细节的把控和写大模拟的耐心,花了一个半小时,AC了3.85,直接交卷退了。第一题AC,第二题AC,第三题85%,第四题AC。下面分享一下大致的题意和对应的代码,就不多说了,最近很累(代码可能会有贴错的情况,如有望指正,感谢~)。 T1-小Y抽奖 题意 n行m列个奖励格子,每次抽奖消耗一个道具。每个格子奖励的数量有限且各不相司。每个格子被抽到一次,剩余的奖励数量-1。剩余的奖励数量为0时,则不会再抽到该格子。小Y抽了好多次,但一直没有抽到最想要的..

米莱虾 9266

[iOS]Runtime2

为了让你在父类中依然能访问当前对象(也就是子类的实例),编译器在底层会生成一个结构体,叫 : 当调用 时,底层调用的函数是 : 拿着(也就是当前的子类对象)作为消息接收者,但是把方法查找的起点定位在了 (父类)这里需要注意的就是仍然是调用者自己,即先讲一下上篇没讲过的,我们如果缓存未命中,那我们就会进入慢速查找,现在我们来详细的讲解在进入慢速查找的瞬间会再看一遍方法列表,然后立刻调用加锁,因为多线程下别人正在动态添加方法或者扩容,不加锁会崩溃类就绪OC的机制就是在编译期只生成了 结构,当类首次被发送消息时(

wzm20070304的博客 240

SO_KEEPALIVE、TCP_KEEPIDLE、TCP_KEEPINTVL、保活包

是一个套接字选项,用于设置是否启用 keepalive 机制。在这段代码中没有涉及到选项的设置。当被设置为非零值时,表示启用 keepalive 机制。keepalive 是一种用于检测连接是否仍然有效的机制。通过定期发送一些特定的探测数据,可以检测到网络连接的异常中断或对端应用程序的崩溃退出。为了避免以上情况,可以启用 keepalive 机制,即使在无数据传输的情况下也定期发送探测数据。如果在一定时间内没有收到对端的响应,就认为连接已经失效,并进行相应的处理。要启用选项,需要使用函数。其中,fd。

m0_46376834的博客 4816

VS Code + KXApp 开发 iOS 报错排查指南,工程、签名、真机、补全、配置

在 VS Code 里用 KXApp 开发 iOS,报错常不在代码而在环境。本文按失败阶段分五类排查:工程没出现 Xcode 视图(查 .xcodeproj 与 xcode-select)、构建失败(No profiles、Team 签名、CocoaPods 用 .xcworkspace)、真机调试失败(信任、开发者模式、设备未准备好)、没补全或 No such module(等索引、清 clangd 冲突)、设置保存不了(装 xcodeproj gem),每类给现象、日志通道和修法。

2501_91590906的博客 198

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

Appuploader 创建 iOS 描述文件详解,Development / Ad Hoc / App Store

搞不清 iOS 描述文件(Provisioning Profile)该选 Development、Ad Hoc 还是 App Store?本文讲清四种类型各装到哪、哪些要绑设备、能不能上架,重点辨析最容易混的 Development 与 Ad Hoc,说明设备或证书变动后为什么要重建、重建后要重新导入签名,并给出不用 Mac 在 Windows/Linux 上用 Appuploader 新建与重建描述文件的实操步骤,附装机"描述文件不匹配"等常见问题排查。

2501_91373349的博客 227

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

苹果的内核跑上了安卓手机:2,631 Star 的 HakiOS 让 XNU 在 Adreno GPU 上画出 118 帧

HakiOS 把苹果开源的 XNU 内核搬上 Android 手机:自研引导器与驱动、RAM 内运行重启即还原,Metal 在 Adreno GPU 上跑出 118 帧。本文拆解其分层架构、双路线性能对比与法律边界。

话梅糖の优快云 Blog 321

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Windows 开发 iOS,Sign in with Apple 苹果登录,KXBuild 真机调试全流程

Sign in with Apple 接入分四步:App ID 开能力并重新生成描述文件,entitlements 加 com.apple.developer.applesignin,用 SignInWithAppleButton 拿 identityToken 交服务端验签,删账号时调 revoke。本文讲清审核指南 4.8 为什么要你提供它、姓名邮箱只给一次、用 user 当主键,并在 Windows 上用 KXBuild 真机测登录,附 1000 报错排查。

2501_91373349的博客 223

iOS 深度链接配置教程,URL Scheme 与 Universal Links,KXBuild 真机验证

深度链接两种:URL Scheme(myapp://)只改 Info.plist 的 CFBundleURLTypes;Universal Links(https://)要开 Associated Domains、在 entitlements 写 applinks 域名、网站放 /.well-known/apple-app-site-association。讲清两者怎么选、onOpenURL 处理代码,在 Windows 上用 KXBuild 装 Debug 包真机验证,附 CDN 缓存和十个不跳转排查。

2501_91600747的博客 282

手机远程控制电脑哪家强?2026年iOS/安卓/鸿蒙横评实测,ToDesk/向日葵谁更流畅

手机远程控制电脑已成刚需,ToDesk凭借全平台覆盖、低延迟、无广告、免费不限速等优势,成为最佳选择。其iOS、安卓、鸿蒙及Mac系统均支持,实测连接快、操作流畅,虚拟键盘、外接键鼠、互动批注等功能体验出色。相较之下,向日葵存在限时踢线、传输慢、广告多等痛点。选购建议:无论用何种手机,首选ToDesk,实现高效便捷的远程办公与协助。

lx08113的博客 297

uni-app iOS 离线打包教程,Windows KXBuild 本地生成 IPA,页面秒推真机

uni-app 云打包老排队、次数受限、改一次 manifest 原生配置就得重打?用 KXBuild 的 HBuilderX 插件在 Windows 本地做 uni-app 离线打包 iOS:导入同版本离线 SDK、填好 AppKey 和证书,就能运行到 iPhone 真机,改页面用"推送"几秒生效,最后生成可上传 App Store Connect 的 ipa,全程不用云打包。附 AppKey 错误、版本不匹配白屏、相机闪退等 9 个常见问题排查。

2501_91510632的博客 185

go消息推送之极光推送 (JPush REST API + SDK,覆盖安卓与iOS)

使用 gorush有个绕不开的问题:国内安卓设备上 FCM 基本不可达,华为、小米、OPPO、vivo 各自为政——此时可用极光推送(JPush)作解决方案。它的思路和前面几家都不一样:App 集成极光 SDK 后拿到统一的 RegistrationID,服务端发一条 REST 请求,极光云端自动把消息路由到 APNs、各家厂商通道或极光自有长连接。这里给出了:一个用纯标准库直接调用极光的;另一个用社区维护的,类型化参数,接口注释与官方文档逐条对应。两个功能相同,可放在一起对比学习。

qq_40467670的博客 172

Cocos Creator3.8.8 + Xcode27.2 编译运行失败

Cocos Creator3.8构建IOS工程后,使用最新的Xcode27.2版本进行真机调试,遇到C++标准库冲突,如is_floating_point、is_arithmetic和is_signed失败,以及webp对齐失败等问题。

HYNN12的博客 376
上一篇: iOS 监听App音量的变化
下一篇: ios 常见系统控件尺寸
皓浩
博客等级 码龄18年 157粉丝 121原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值