ios - objective c block that waits for another delegate -
i have watchkit app calls viewcontroller on iphone app. have delegate network connection. i'm trying use block don't tightly couple appdelegate , view controller closely. how can notify block when delegate finished?
viewcontroller.m
-(void)getwatchdatawithcompletion:(void(^)(bool gotdata))completion{ [self setupappforwatch]; completion(yes); } -(void)finishedmessageparse:(nsmutabledata *)messagedata{ //the delegate finish tell block completion done. } -(void)setupappforwatch{ [network call]; }
appdelegate.m
-(void)application:(uiapplication *)application handlewatchkitextensionrequest:(nsdictionary *)userinfo reply:(void (^) (nsdictionary *))reply{ [vc getwatchdatawithcompletion:^(bool gotdata){ if (gotdata){ //i'm done reply dictionary reply(@{@"data":serlizeddata}) }];
add new property in viewcontroller:
@property (nonatomic, strong) void(^completion)(bool gotdata); -(void)getwatchdatawithcompletion:(void(^)(bool gotdata))completion{ [self setupappforwatch]; self.completion = completion; } -(void)finishedmessageparse:(nsmutabledata *)messagedata{ if (self.completion){ self.completion(yes); } }
Comments
Post a Comment