PFFileObject
一种存储对象类型,文件,image, vidoe ,binary data等。
PFFileState
文件状态,记录文件的类型,名字,ulr。
PFAsyncTaskQueue
在串行队列中,采用异步的方式,来执行任务。
// 创建串行队列
_syncQueue = dispatch_queue_create("com.parse.asynctaskqueue.sync", DISPATCH_QUEUE_SERIAL);
// 串行队列中,异步执行
- (BFTask *)enqueue:(BFContinuationBlock)block {
BFTaskCompletionSource *source = [BFTaskCompletionSource taskCompletionSource];
dispatch_async(_syncQueue, ^{
...
});
return source.task;
}
// 串行队列执行 block
- (void)_performDataAccessBlock:(dispatch_block_t)block {
PFThreadsafetySafeDispatchSync(_synchronizationQueue, block);
}
- (NSString *)name {
__block NSString *name = nil;
[self _performDataAccessBlock:^{
name = self.state.name;
}];
return name;
}
- (NSString *)url {
__block NSString *url = nil;
[self _performDataAccessBlock:^{
url = self.state.secureURLString;
}];
return url;
}
// 异步到UI 返还主队列
- (void)_performProgressBlockAsync:(PFProgressBlock)block withProgress:(int)progress {
if (!block) {
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
block(progress);
});
}
// 采用信号量来保持 异步执行完毕
- (BOOL)save:(NSError **)error {
return [[[self saveInBackground] waitForResult:error] boolValue];
}
- (NSData *)getData:(NSError **)error {
return [[self getDataInBackground] waitForResult:error];
}
- (NSInputStream *)getDataStream:(NSError **)error {
return [[self getDataStreamInBackground] waitForResult:error];
}
网友评论