title: Apple watch app does not work when iPhone app is in terminated state?
body: <p>I am working on an apple watch app, but facing a weird issue, i.e. my watch app works only when I manually open the iPhone app or when iPhone app is in background. When I terminate my iPhone app and test apple watch app then it does not work any more.</p>
  
  <p>Here I am mentioning watch app flow:</p>
  
  <ul>
  <li>When apple watch app starts, I call a web api to fetch response from server.</li>
  <li>I used <code>openParentApplication:reply:</code> method to call web api from parent app</li>
  <li>I understand that, I will have to call web api method in a background thread because, openParentApplication:reply: method automatically open the parent app in iPhone and suspends in a mean time, so if we are processing a time taking task using this method then we should use a background thread as mentioned under <a href="https://developer.apple.com/watchkit/tips/" rel="nofollow noreferrer">WatchKit Development Tips</a>. So I am using a background thread to call web api.</li>
  <li>When I get response I pass it to watch app.</li>
  </ul>
  
  <p>Here is the attached snippet:</p>
  
  <p><strong>Watch App - InitialInterfaceController.m</strong></p>
  
  <pre><code>- (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);
                                                 }
                                             }];
  
  }
  </code></pre>
  
  <p><strong>iPhone App - AppDelegate.m</strong></p>
  
  <pre><code>- (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), ^{
          // Get 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});
                            });
  
                        }];
          }
  }
  </code></pre>
  
  <p><strong>iPhone App - APIHandler.m</strong></p>
  
  <pre><code>- (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:@"&amp;%@", 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:&amp;error];
                                         success(details);
                                     }
                                     else{
                                         failure(@"Connection Error!");
                                     }
                                 }];
  }
  </code></pre>
  
  <p>But this approach is not working for me. </p>
  
  <p>I found one more issue in watch app simulator i.e.
   <code>- (void)awakeWithContext:(id)context</code> for my initial view controller is called, but <code>- (void)willActivate</code> method is not being called sometimes and I just see watch app spinner. Some times it works. It’s quite strange. I have around 15 controls (including all groups) in initial interface controller added using storyboard.</p>
  
  <p>I have also referred <a href="https://stackoverflow.com/questions/29083727/watchkit-not-calling-willactivate-method">Watchkit not calling willActivate method</a> and modified my code but still facing same issue.</p>
  
  <p>Can any one let me know why is this issue persisting in my app?</p>