Failed to load message in Today Widget

I am in the middle of developing my widget. Since we have already placed our application with widget integration. But after a few days, I ran into a widget problem today in iOS. I wrote code for two cases. The first time the widget initially loads the first time the application is launched, it calls a web service and receives data over the Internet, and then we save it to the default user for later use.

Now, the next time the user pulls out the notification menu, we first display our old saved content to the user, and then we get it from the web service and save the default user, and then load the table again.

For the above operation, I encounter a content size problem for the table, a flickering problem and an “unable to load” message in some cases.

Now let's look at the code below, I am making a web call below the method, and after responding to the web service, I just process the completion handler.

- (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler { // Perform any setup necessary in order to update the view. // If an error is encountered, use NCUpdateResultFailed // If there no update required, use NCUpdateResultNoData // If there an update, use NCUpdateResultNewData [self getBookedAppointmentsNew:completionHandler]; } 

So please share your experiences and ideas with me.

+6
source share
2 answers

In general, I saw the message “Unable to load” whenever a widget crashed. The widget tries to load itself, and if it crashes several times, it simply displays the message "Unable to load." Debug your widget and make sure that nothing causes it to crash

+4
source

Finally, I found a way to solve the problem. Please see the code below.

In the viewDidLoad () method, I just set the preferred size of the content of the view to the base height that I need when I start to show my bottom view, and then I made a web service call to retrieve the data. After receiving the data, I again set the preferred content size of the TodayWidget view.

 -(void)viewDidLoad { [super viewDidLoad]; self.bottomView.frame = CGRectMake(self.bottomView.frame.origin.x, 0.0, self.bottomView.frame.size.width, self.bottomView.frame.size.height); self.preferredContentSize = CGSizeMake(self.view.frame.size.width, self.bottomView.frame.size.height); [self getBookedAppointmentsNew]; } -(void)getBookedAppointmentsNew { //-- After web-service response (positive/negative), I have set again the preferred content size. self.bottomView.frame = CGRectMake(self.bottomView.frame.origin.x, self.scrollView.frame.size.height, self.bottomView.frame.size.width, self.bottomView.frame.size.height); self.preferredContentSize = CGSizeMake(self.view.frame.size.width, (self.bottomView.frame.origin.y + self.bottomView.frame.size.height)); } 

I took the following steps to solve the problems “Unable to load” and “Screen flicker” using the “Today” extension.

+2
source

Source: https://habr.com/ru/post/981433/


All Articles