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

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -