您的位置:首页 > 移动开发

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

2013-01-11 17:46 489 查看
对于一个完善的应用来说,需要在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系统下就比较麻烦,只能从流程上打主意,不利于实现。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: