ios应用UIApplication前后台切换代理方法在不同ios系统下的差异

对于一个完善的应用来说,需要在UIApplication的各个代理方法里进行相应的处理,特别是前后台切换时一般需要进行一些特定的操作;而对于不同版本的ios系统,其代理方法居然也存在着一些差异,不由得让人大跌眼镜。

IOS4:

// Pressing the home button
Will resign active.
Did enter background.
// Tapping app icon on Springboard
Will enter foreground.
Did become active.

// Pressing the lock button
Will resign active.
// Unlocking the device
Did become active.

IOS5及以后:

// Pressing the home button
Will resign active.
Did enter background.
// Tapping app icon on Springboard
Will enter foreground.
Did become active.

// Pressing the lock button
Will resign active.
Did enter background.
// Unlocking the device
Will enter foreground.
Did become active.

可以看到,ios4的锁屏和解锁不会触发didenterbackground方法和willenterforeground方法;而ios5中的didenterbackground方法通过UIApplicationState state = [[UIApplication sharedApplication] applicationState]可以区分是由按home触发还是按锁屏键触发;锁屏时状态为inactive,home键为background.而在willresignactive方法中,两种行为的state均为active。从个人的使用上来看,通过didenterbackground中的state可以很好的在实现上加以区分以实现相异的行为,而在4x系统下就比较麻烦,只能从流程上打主意,不利于实现。


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值