简体   繁体   English

Today Widget扩展的问题

[英]Issues with Today Widget extension

I have a Today Widget for my app, however I have been told about an issue with it. 我的应用程序有一个Today Widget,但是我被告知它的问题。

Basically, what seems to be happening (I can't test this for myself) is that the widget will sometimes just display 'unable to load' and other times it will just display with a height of 0. 基本上,似乎正在发生的事情(我无法为自己测试)是窗口小部件有时只显示“无法加载”,有时它只显示高度为0。

I can't really see why this is happening. 我真的不明白为什么会这样。 I've tested it out on my device and the simulator for weeks now and have never ran into this issue. 我已经在我的设备和模拟器上测试了几周,并且从未遇到过这个问题。

I was wondering if it could possibly be down to the refresh code: 我想知道它是否可能归结为刷新代码:

    func widgetPerformUpdateWithCompletionHandler(completionHandler: ((NCUpdateResult) -> Void)!) {
    // Perform any setup necessary in order to update the view.

    var defaults = NSUserDefaults(suiteName: "group.AffordIt")
    var newCheck = defaults.boolForKey("new")

    if newCheck == true {
        completionHandler(NCUpdateResult.NewData)
    } else {
        completionHandler(NCUpdateResult.NoData)
    }
}

'newCheck' is true whenever something changes within my app that needs to be displayed in the widget. 每当我的应用程序中的某些内容发生变化,需要在窗口小部件中显示时,'newCheck'才会生效。

Does anyone know what the possible causes of these issues are? 有谁知道这些问题的可能原因是什么?

"unable to load" message appears if your extension crashes often. 如果您的扩展程序经常崩溃,则会显示“无法加载”消息。 You can try to re-enable it by removing and adding the extension again. 您可以尝试通过再次删除和添加扩展来重新启用它。

Are you using your own view controller and xib instead of using storyboard? 您使用自己的视图控制器和xib而不是使用故事板吗? If yes, it is probably that you didn't set the preferredContentSize in your view controller. 如果是,可能是您没有在视图控制器中设置preferredContentSize。

try to put the following code in the init function of ur view controller: 尝试将以下代码放在ur视图控制器的init函数中:

    self.preferredContentSize = CGSizeMake(320, 100);

I have just began the extension programming today so I am not sure is it really helpful for u or not. 我今天刚开始进行扩展编程,所以我不确定它对你是否真的有用。 Here is the result in my own widget: 这是我自己的小部件中的结果:

在此输入图像描述

  1. Press Edit button in today extensions 按今日扩展中的编辑按钮
  2. Remove your extension 删除您的扩展程序
  3. Add your extension again. 再次添加扩展程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM