【发布时间】:2014-11-26 06:49:24
【问题描述】:
我希望日历访问用户的 iPhone,因为我正在使用异步调用
__block NSMutableArray* someData;
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
//We are going to fetch events from today to the next 1 year
if (granted) {
//Processing
[someData addObject:@"Something Added"]
}
}];
我基本上想做一些处理,然后向在另一个对象中执行的主线程发出信号,表明处理已经在 someData 上完成,它现在应该访问它。
我曾尝试将其包装在这样的调度组中
dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group,dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ {
calendarData = [calender returnCalenderEvents];
});
dispatch_group_notify(group,dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ {
NSLog(@"%@",calendarData);
});
但是由于调用是异步的,它仍然会在完成任何实际完成之前通知组完成。
基本上我怎样才能在异步调用上向主线程发出处理已完成的信号,获取结果并开始进行自己的处理
【问题讨论】:
-
为什么不访问辅助线程中的主线程。然后只从这里通知。
标签: ios objective-c multithreading asynchronous grand-central-dispatch