I am trying to create Today Extension (aka Widget) for my existing iOS 7+ application. In iOS Simulator everything works fine (most of the time), but on my devices the widget is empty - only the title / name is displayed, but there is no content.
I found several topics related to similar problems, but they were all related to some init problems in Swift applications. I use Objective-c, not Swift.
This is what I did:
- Added a new Today Extension target for my application. The corresponding scheme was created automatically.
- The problem also occurs when the default immutable widget is used. I just added init methods to find out if they were called correctly. Thus, the widget should show the default
Hello World label.
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];
When you select a widget layout and run it in the simulator, the widget is displayed correctly after selecting "Today" as the container. Additionally, initWithCoder written.
At the first start of the device, everything works as expected: Today screens appear and widgets are displayed. My widget is also, but without any content.
Xcode then shows the following message:
Lost connection to "Test Device" - reconnect to "Test Device" and run "com.example.MyApp.Widget" again, or if "com.example.MyApp.Widget" still works, you can attach Debug to it > Attach to Process> com.example.MyApp.Widget.
Nothing is logged, I assume this is due to a lost connection. But why is the widget empty?
I looked at 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)
Thank you very much!
source share