在iOS模拟器7.1中,下面是简单的代码:
出于什么原因,在第二种情况下,搁浅被称为两次?请注意,在iOS 8.0的情况下,2.显示:-激活-辞职-回退
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController {}
- (void)backgrounding {
NSLog(@"backgrounding");
}
- (void)resigning {
NSLog(@"resigning");
}
- (void)activing {
NSLog(@"activing");
}
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backgrounding) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resigning) name:UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(activing) name:UIApplicationDidBecomeActiveNotification object:nil];
}
@end发布于 2014-09-15 21:16:21
iOS 7(至少在模拟器中)发送两个回退事件。您只需编写您的应用程序,以处理多个后台事件优雅。
我通过创建一个记录每个事件的自定义UIApplication子类以及它的内部GraphicsServices事件(如果存在这样的话)来检查这一点:
#import "MyApplication.h"
@interface NSObject (hack)
- (id)_gsEvent;
@end
@implementation MyApplication
- (void)sendEvent:(UIEvent *)event {
NSLog(@"event=%@", event);
if ([event respondsToSelector:@selector(_gsEvent)]) {
NSLog(@"_gsEvent=%@", event._gsEvent);
}
[super sendEvent:event];
}
@end以下是在多任务屏幕中删除应用程序的输出:
2014-09-15 16:14:32.894 background[19438:70b] event=<UIInternalEvent: 0x8c148e0>
2014-09-15 16:14:32.894 background[19438:70b] _gsEvent=<GSEvent 0xd9149f0>{type = 32, windowLoc = (0.000000, 0.000000)}
2014-09-15 16:14:32.895 background[19438:70b] event=<UIInternalEvent: 0x8c148e0>
2014-09-15 16:14:32.895 background[19438:70b] _gsEvent=<GSEvent 0x8f1ac20>{type = 7d7, windowLoc = (0.000000, 0.000000)}
2014-09-15 16:14:32.896 background[19438:70b] backgrounding
2014-09-15 16:14:32.943 background[19438:70b] event=<UIInternalEvent: 0x8c148e0>
2014-09-15 16:14:32.944 background[19438:70b] _gsEvent=<GSEvent 0x8b22c90>{type = 7d7, windowLoc = (0.000000, 0.000000)}
2014-09-15 16:14:32.944 background[19438:70b] backgrounding您可以看到有两个单独的GraphicsServices事件(具有不同的地址),每个UIApplicationDidEnterBackgroundNotification都有一个事件。
https://stackoverflow.com/questions/25856186
复制相似问题