[英]Today Widget has no content on iOS 8 device
I am trying to create a Today Extension (aka Widget) for my existing iOS 7+ app. 我正在尝试为我现有的iOS 7+应用程序创建Today Extension(aka Widget)。 In iOS Simulator everything works fine (most of the time) but on my devices the widget is empty - only the header/name is shown but no content. 在iOS模拟器中一切正常(大部分时间),但在我的设备上,小部件是空的 - 只显示标题/名称但没有内容。
I found several threads dealing with similar issues but they were all related to some init-problems in Swift apps. 我发现有几个线程处理类似的问题,但它们都与Swift应用程序中的一些init问题有关。 I am using Objectiv-c not Swift. 我使用的是Objectiv-c而不是Swift。
This is what I did: 这就是我做的:
Hello World
label. 因此,窗口小部件应显示默认的Hello World
标签。 This is the code: 这是代码:
@interface TodayViewController () <NCWidgetProviding>
@end
@implementation TodayViewController
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self)
NSLog(@"initWithCoder");
return self;
}
- (id)init {
self = [super init];
if (self)
NSLog(@"init");
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
NSLog(@"initWithNibName");
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (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
completionHandler(NCUpdateResultNewData);
}
@end
When selecting the widget scheme and running it in simulator the widget is displayed correctly after selecting "Today" as container. 选择窗口小部件方案并在模拟器中运行时,在选择“今天”作为容器后,窗口小部件会正确显示。 Additionally initWithCoder
is logged. 此外, initWithCoder
记录initWithCoder
。
When running on device at first everything works as expected: The Today Screens comes up and the widgets are shown. 在设备上运行时,一切都按预期工作:今日屏幕出现并显示小部件。 My widget as well, but without any content. 我的小部件也是,但没有任何内容。
Then Xcode shows the following message: 然后Xcode显示以下消息:
Lost connection to "Test Device" - Restore the connection to "Test Device" and run "com.example.MyApp.Widget" again, or if "com.example.MyApp.Widget" is still running, you can attach to it by selecting Debug > Attach to Process > com.example.MyApp.Widget. 丢失与“测试设备”的连接 - 恢复与“测试设备”的连接并再次运行“com.example.MyApp.Widget”,或者如果“com.example.MyApp.Widget”仍在运行,则可以通过选择Debug> Attach to Process> com.example.MyApp.Widget。
Nothing is logged, I assume this is because of the lost connection. 没有记录,我认为这是因为连接丢失。 But why is the widget empty? 但为什么小部件是空的?
I looked into the device logs but there are no crashes. 我查看了设备日志,但没有崩溃。 The problem is the same on my iPhone 6 (iOS 8.0) and iPad Air 2 (iOS 8.1) 问题在我的iPhone 6(iOS 8.0)和iPad Air 2(iOS 8.1)上是一样的
Thank you very much! 非常感谢你!
After a couple of days of searching I finally found the solution: 经过几天的搜索,我终于找到了解决方案:
My project (the containing app of the widget) and the widget itself did not include the arm64 architecture. 我的项目(小部件的包含应用程序)和小部件本身不包含arm64架构。 As the Apple docs describe this is not a valid configuration: 正如Apple文档描述的那样,这不是一个有效的配置:
A containing app that links to an embedded framework must include the arm64 (iOS) or x86_64 (OS X) architecture build setting or it will be rejected by the App Store. 链接到嵌入式框架的包含应用程序必须包含arm64(iOS)或x86_64(OS X)体系结构构建设置,否则App Store将拒绝该应用程序。 (As described in Creating an App Extension, all app extensions must include the appropriate 64-bit architecture build setting.) (如创建应用程序扩展中所述,所有应用程序扩展必须包含相应的64位体系结构构建设置。)
When x64 is missing the app will not only be rejected but also prevents the widget from showing up in the first place. 当缺少x64时,应用程序不仅会被拒绝,还会阻止小部件首先显示。
I added the widget to an existing projects which was not configured for x64 yet and it seems that the same build settings have been applied to the widget automatically. 我将窗口小部件添加到尚未为x64配置的现有项目中,并且似乎相同的构建设置已自动应用于窗口小部件。 It would have avoided a lot of work if Xcode would have shown any warning or hint about this problem... 如果Xcode会对这个问题发出任何警告或暗示,那本可以避免很多工作......
I did the following to solve the problem: 我做了以下解决问题:
Build Settings
Tab and navigate to the Architectures
section. 选择Build Settings
选项卡,然后导航到Architectures
部分。 Architectures
to Standard architectures (armv7, arm64)
将Architectures
设置为Standard architectures (armv7, arm64)
Valid Architectures
to armv7 armv7s armv8 arm64
将Valid Architectures
设置为armv7 armv7s armv8 arm64
Build Active Architectures Only
to No
Build Active Architectures Only
将Build Active Architectures Only
设置为No
After this the widget works correctly both in the simulator and on my test devices. 在此之后,小部件在模拟器和我的测试设备上都能正常工作。
add 加
self.preferredContentSize = CGSizeMake(320, 60);
to 至
-(void)viewdidload{}
in viewcontroller.m of extension. 在viewcontroller.m的扩展名中。
This method solved my issue. 这个方法解决了我的问题。
I hope it can also help u. 我希望它也可以帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.