JSGCDDipatcher 是围绕 GCD 的小型 Objective-C 封装,提供简单接口以将块提交给 GCD,可用于串行或并发队列。
[[JSGCDDipatcher sharedDispatcher] dispatch:^{
// Busy Work
}];
[[JSGCDDipatcher sharedDispatcher] dispatch:^{
// Busy Work
} priority:DISPATCH_QUEUE_PRIORITY_DEFAULT];
[target dispatchOnSerialQueue:^{
// Busy serial work
}];
[[JSGCDDipatcher sharedDispatcher] submitSerialQueueCompletionListener:^{
// Serial jobs complete
}];
当您有一个重要任务并且如果应用突然被置于后台不会中断时,调用此方法。
[target dispatchBackgroundTask:^(UIBackgroundTaskIdentifier identifier) {
if(identifier == UIBackgroundTaskInvalid) {
// Almost out of time to run the task
} else {
// Good to go
}
} priority:DISPATCH_QUEUE_PRIORITY_DEFAULT];