iOS 8 today widget stops working after a while

前端 未结 4 457
青春惊慌失措
青春惊慌失措 2021-01-30 11:38

I\'ve made a today widget for the german ice hockey league DEL.

I\'m loading the next games from our server an show them in a tableView. The loading process is started i

4条回答
  •  被撕碎了的回忆
    2021-01-30 12:11

    As others have mentioned, this is caused by not having previous called the completionHandler after widgetPerformUpdateWithCompletionHandler has been called. You need to make sure that completionHandler is called no matter what.

    The way I suggest handling this is by saving the completionHandler as an instance variable, and then calling it with failed in viewDidDisappear:

    @property(nonatomic, copy) void (^completionHandler)(NCUpdateResult);
    @property(nonatomic) BOOL hasSignaled;
    
    - (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler {
        self.completionHandler = completionHandler;
        // Do work.
    }
    
    - (void)viewDidDisappear:(BOOL)animated {
      [super viewDidDisappear:animated];
      if (!self.hasSignaled) [self signalComplete:NCUpdateResultFailed];
    }
    
    - (void)signalComplete:(NCUpdateResult)updateResult {
      NSLog(@"Signaling complete: %lu", updateResult);
      self.hasSignaled = YES;
      if (self.completionHandler) self.completionHandler(updateResult);
    }
    

提交回复
热议问题