对于一个完善的应用来说,需要在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系统下就比较麻烦,只能从流程上打主意,不利于实现。
时间: 2024-10-23 07:50:55