"Unable to Load" message in Today's Widget
Asked Answered
L

3

7

I'm in between with my widget development. As we have already placed our app with widget integration. But in now a days, I'm facing problem with today's widget in iOS. I've written a code for two cases. First time when widget is initially loading first time with application launch it calls web-service and fetches data over the internet and then We store them into user default for later use.

Now when next time, user pull down the notification menu, we display our old stored content first to user and then we fetch it from web-service and store in user-default and then reloading table once again.

For above operation, I'm facing content size issue for table, flickering issue and "unable to load" message in some cases.

Now take a look for below code, I'm making a web-call in below method and after the response of web-service, I just handle 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's no update required, use NCUpdateResultNoData
    // If there's an update, use NCUpdateResultNewData
    [self getBookedAppointmentsNew:completionHandler];
}

So, please share your experience and ideas with me.

Lyell answered 23/1, 2015 at 6:20 Comment(3)
Just to be clear, you're calling your web service, and you don't call the completion handler until after that call finishes?Parochialism
Yes, I do the same thing.. I call web-service and on the completion of the service, I complete it with the completion handler.Lyell
Actually, I need to make a web-service call each time to fetch my latest events for the customers but until I fetch them I'm trying to show the previously fetched data to the customers. So, there is no chance of screen flickering. I want to refresh the view with new contents without any side effects.Lyell
B
5

In general I saw the "Unable to load" message whenever there was a crash in the widget. The widget tries to load itself and if it repeatedly crashes then it will just show the "Unable to load" message. Debug your widget and make sure nothing is causing it to crash

Benighted answered 5/1, 2016 at 21:40 Comment(1)
I had fixed my issues in the widget but it was still showing "unable to load". Turns out iOS wasn't even trying to load the widget if it crashed enough times. I had to reboot the phone and then it loaded. Thanks for the tip!Epiphytotic
L
2

Finally, I got the way to solve the issue. Please take a look at the code below.

In the viewDidLoad() method, I have just set the preferred content size of the view to the basic height which I need at startup to show my bottom view, and then I have made a web service call to fetch the data. After fetching the data, I have 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 have followed the steps above to resolve issues regarding "Unable to load" and "screen flickers" with the Today Extension.

Lyell answered 30/1, 2015 at 11:14 Comment(1)
Great approach, the goal for me was "self.view.frame.size.width"Frenchpolish
M
0

Your widget interface's layout constraints may not unique. Views without any layout constraints may clip their content or overlap other views.

Miscellany answered 13/8, 2020 at 8:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.