iOS 8 today widget stops working after a while

前端 未结 4 458
青春惊慌失措
青春惊慌失措 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:05

    An additional problem is that once widgetPerformUpdateWithCompletionHandler: is stopped being called, there will never be another completion handler to call. I haven't found a way to make the system call widgetPerformUpdateWithCompletionHandler: again. Therefore, make sure your widget will also try to reload data through viewWillAppear: as a fallback, or some users might be stuck with a non-loading widget.

    0 讨论(0)
  • 2021-01-30 12:06

    Calling the completionHandler with NCUpdateResultNewData within widgetPerformUpdateWithCompletionHandler before an async call comes back and calls it again with NCUpdateResultNewData or NCUpdateResultFailed seems to work.

    0 讨论(0)
  • 2021-01-30 12:11

    I've got the same problem and I resolved it by calling completionHandler(NCUpdateResultNoData); right after your network request even when the response hasn't been returned. I found that if completion handler is not called the widgetPerformUpdateWithCompletionHandler will no longer get invoked, and therefore there won't be any more updates. Also make sure you call completion handler in all branches after your request call returns.

    0 讨论(0)
  • 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);
    }
    
    0 讨论(0)
提交回复
热议问题