iOS 8 今天小部件在一段时间后停止工作 [英] iOS 8 today widget stops working after a while

查看:16
本文介绍了iOS 8 今天小部件在一段时间后停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为德国冰球联赛 DEL 制作了一个今日小部件.

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

我正在从我们的服务器加载下一个游戏,并在 tableView 中显示它们.加载过程在建议的方法widgetPerformUpdateWithCompletionHandler"中开始.最初我在viewWillAppear"中加载一些缓存数据.

I'm loading the next games from our server an show them in a tableView. The loading process is started in the proposed method "widgetPerformUpdateWithCompletionHandler". Initially i'm loading some cached data in "viewWillAppear".

到目前为止一切都很好!

Everything works great so far!

但过了一段时间(一天),小部件停止工作.当我打开通知中心时,小部件看起来很正常,但它再也不会更新了.我必须从通知中心删除小部件并再次添加它.之后,小部件工作了一天,然后又停止工作.

But after a while (one day) the widget stops working. When I open the notification center the widget appears normal, but it is never updated again. I have to remove the widget from the notification center and have to add it again. After that the widget works for a day and then again it stops working.

为了查看小部件正在做什么,我在表格视图上方添加了一个带有状态文本的简单白色视图,同时在widgetPerformUpdateWithCompletionHandler"中加载数据以查看小部件是否正在执行任何操作.小部件工作时会出现白色视图.当它不工作时,状态视图不会出现.所以我认为小部件在通知中心处于活动状态一段时间后,不会调用widgetPerformUpdateWithCompletionHandler"方法.

To see what the widget ist doing, I've added a simple white view with a status text above the table view while loading the data in "widgetPerformUpdateWithCompletionHandler" to see if the widget is doing anything. The white view appears when the widget is working. When it is not working the status view doesn't appear. So I think the method "widgetPerformUpdateWithCompletionHandler" isn't called after the widget is active in the notification center for a while.

我不知道是什么导致小部件停止工作.有什么想法吗?

I've got no clue what causes the widget to stop working. Any ideas?

推荐答案

我遇到了同样的问题,我通过调用 completionHandler(NCUpdateResultNoData); 解决了它在您的网络请求之后,即使没有返回响应.我发现如果不调用完成处理程序 widgetPerformUpdateWithCompletionHandler将不再被调用,因此不会有任何更新.还要确保在请求调用返回后在所有分支中调用完成处理程序.

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.

这篇关于iOS 8 今天小部件在一段时间后停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆