我有一个像这样的方法:
- (void)showPermissionRequestsWithCompletionHandler:(void (^)())completionHandler
{
completionHandler();
}
我喜欢将completionHandler存储在私有var中,以便我可以在适当的时间发送它。有谁知道如何做到这一点?
我现在有:
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;
}
但有些事告诉我这不是正确的方法。