ios - Apple watch app does not work when iPhone app is in terminated state? -


i working on apple watch app, facing weird issue, i.e. watch app works when manually open iphone app or when iphone app in background. when terminate iphone app , test apple watch app not work more.

here mentioning watch app flow:

  • when apple watch app starts, call web api fetch response server.
  • i used openparentapplication:reply: method call web api parent app
  • i understand that, have call web api method in background thread because, openparentapplication:reply: method automatically open parent app in iphone , suspends in mean time, if processing time taking task using method should use background thread mentioned under watchkit development tips. using background thread call web api.
  • when response pass watch app.

here attached snippet:

watch app - initialinterfacecontroller.m

- (void)awakewithcontext:(id)context {     [super awakewithcontext:context]; }  - (void)willactivate {     [super willactivate];     [self getdetails]; }   - (void)getdetails{     //open parent app     [wkinterfacecontroller openparentapplication:@{@“request”:@“details”}                                            reply:^(nsdictionary *replyinfo, nserror *error) {                                                if (!error) {                                                    nslog(@“success”);                                                    [self parsekpi:replyinfo];                                                }                                                else{                                                    nslog(@"error - %@", error.localizeddescription);                                                }                                            }];  } 

iphone app - appdelegate.m

- (void)application:(uiapplication *)application handlewatchkitextensionrequest:(nsdictionary *)userinfo               reply:(void (^)(nsdictionary *))reply{     nsstring *request = [userinfo objectforkey:@“request”];      dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_background, 0), ^{         // details         if ([request isequaltostring:@"details"]) {             apihandler *api = [[apihandler alloc] init];             [api getdetailsusername:@“my_user_name”                           onsuccess:^(nsdictionary *details) {                           dispatch_async(dispatch_get_main_queue(), ^{                               reply(details);                           });                        } onfailure:^(nsstring *message) {                           dispatch_async(dispatch_get_main_queue(), ^{                               reply(@{@"error":message});                           });                        }];         } } 

iphone app - apihandler.m

- (void) getdetailsusername:(nsstring *)username              onsuccess:(void(^)(nsdictionary * details))success              onfailure:(void(^)(nsstring *message))failure{          nsstring *urlstring = [nsstring stringwithformat:@"%@%@", host, details_api];         urlstring = [urlstring stringbyappendingformat:@"?username=%@",username];         urlstring = [urlstring stringbyappendingformat:@"&%@", self.apikeyparameter];          nsurl *url = [nsurl urlwithstring:urlstring];         nsmutableurlrequest *mutableurl = [nsmutableurlrequest requestwithurl:url];         [nsurlconnection sendasynchronousrequest:mutableurl                                            queue:[nsoperationqueue mainqueue]                                completionhandler:^(nsurlresponse *response, nsdata *data, nserror *connectionerror) {                                    if (!connectionerror) {                                        nserror *error = nil;                                        nsdictionary *details = [nsjsonserialization jsonobjectwithdata:data                                                                                                options:nsjsonreadingmutableleaves                                                                                                  error:&error];                                        success(details);                                    }                                    else{                                        failure(@"connection error!");                                    }                                }]; } 

but approach not working me.

i found 1 more issue in watch app simulator i.e. - (void)awakewithcontext:(id)context initial view controller called, - (void)willactivate method not being called , see watch app spinner. times works. it’s quite strange. have around 15 controls (including groups) in initial interface controller added using storyboard.

i have referred watchkit not calling willactivate method , modified code still facing same issue.

can 1 let me know why issue persisting in app?

you'll need handle request in iphone app bit differently in order app not killed off os. i've shared similar answer here: https://stackoverflow.com/a/29848521/3704092


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -