我有这样的方法:
- (void)showPermissionRequestsWithCompletionHandler:(void (^)())completionHandler
{
completionHandler();
}
我喜欢将 completionHandler 存储在一个私有变量中,这样我就可以在适当的时候调度它。有谁知道如何做到这一点?
我现在有:
typedef void (^VoidBlockType)();
@interface CMPermissionCenter : NSObject <UIAlertViewDelegate>
{
@private
VoidBlockType _didShowPermissionRequestsBlock;
}
- (void)showPermissionRequestsWithCompletionHandler:(void (^)())completionHandler
{
_didShowPermissionRequestsBlock = [completionHandler retain];
[self doSomeWork];
}
- (void)doSomeWork
{
_didShowPermissionRequestsBlock();
[_didShowPermissionRequestsBlock release];
_didShowPermissionRequestsBlock = nil;
}
但是有些事情告诉我这不是正确的方法。