Skip to content

Instantly share code, notes, and snippets.

@ycditchf
Last active December 22, 2017 11:21
Show Gist options
  • Save ycditchf/bf36ec3608ad529e2b714ae6f6e30fa8 to your computer and use it in GitHub Desktop.
Save ycditchf/bf36ec3608ad529e2b714ae6f6e30fa8 to your computer and use it in GitHub Desktop.
监测runloop
- (void)setupRunloopObserver
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
CFRunLoopRef runloop = CFRunLoopGetCurrent();
CFRunLoopObserverRef enterObserver;
enterObserver = CFRunLoopObserverCreate(CFAllocatorGetDefault(),
kCFRunLoopEntry | kCFRunLoopExit,
true,
-0x7FFFFFFF,
BBRunloopObserverCallBack, NULL);
CFRunLoopAddObserver(runloop, enterObserver, kCFRunLoopCommonModes);
CFRelease(enterObserver);
});
}
static void BBRunloopObserverCallBack(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info) {
switch (activity) {
case kCFRunLoopEntry: {
NSLog(@"enter runloop...");
}
break;
case kCFRunLoopExit: {
NSLog(@"leave runloop...");
}
break;
default: break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment