iOS extracts: Responding to interruptions

--from 《iPhone Application Development For Dummies - Neal Goldstein》


Various events besides termination can interrupt your application to allowthe user to respond — for example, incoming phone calls, SMS messages,calendar alerts, or the user pressing the Sleep button on an iPhone. Suchinterruptions may only be temporary. If the user chooses to ignore an inter-ruption, your application continues running as before. If the user decides toanswer the phone or reply to an SMS message, however, your application willbe terminated.

Figure 6-8 shows the sequence of events that occurs during the arrival of aphone call, SMS message, or calendar alert. Here’s what that looks like stepby step:

1. The system detects an incoming phone call or SMS message, or a cal-endar event occurs.

2. The system sends your application delegate theapplicationWillResignActive:message.

Because these interruptions cause a temporary loss of control by yourapplication — meaning that touch events are no longer sent to yourapplications — it is up to you to prevent what is known in the trade asa “negative user experience.” For example, if your application is a game,you should pause the game. 


  1. The system displays an alert panel with information about the event.

    The user can choose to ignore the event or respond to it.

  2. If the user ignores the event, the system sends your application del-egate theapplicationDidBecomeActive:message and resumes thedelivery of touch events to your application.

    You can use this delegate method to restore the application to the stateit was in before the interruption. What you do depends on your applica-tion. In some applications, it makes sense to resume normal processing.In others — if you’ve paused a game, for example — you could leave thegame paused until the user decides to resume play.

  3. If the user responds to the event, instead of ignoring it, the systemsends your application delegate theapplicationWillTerminate:message.

    Your application should do what it needs to do in order to terminategracefully.

The way the Sleep/Wake button is handled is a little different. When theapplication enters or resumes from a sleep state, two messages are sent tothe application delegate:applicationWillResignActive:andapplica-tionDidBecomeActive:, respectively. In this case, your application alwaysresumes, though the user might immediately launch a different application. 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值