Today Widget has no content on iOS 8 device

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]; // 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 no update required, use NCUpdateResultNoData // If there an update, use NCUpdateResultNewData completionHandler(NCUpdateResultNewData); } @end 

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!

+6
source share
2 answers

After several days of searching, I finally found a solution:

My project (containing the widget application) and the widget itself did not include the arm64 architecture. Because Apple docs describe this invalid configuration:

A containing application that references the embedded framework must include arm64 (iOS) or x86_64 (OS X), or it will be rejected by the App Store. (As described in the "Creating an Application Extension" section, all application extensions must include the appropriate 64-bit architecture to build the customization.)

When x64 is missing, the application will be rejected not only, but also prevent the widget from appearing in the first place.

I added a widget to existing projects that are not yet configured for x64, and it seems that the same build settings were applied to the widget automatically. This would avoid a lot of work if Xcode showed any warning or a hint of this problem ...

I decided to do the following:

  • Click on the project entry in the Project Navigator and select the purpose of the application.
  • Select the Build Settings tab and go to the Architectures section.
  • Install Architectures in Standard architectures (armv7, arm64)
  • Install Valid Architectures in armv7 armv7s armv8 arm64
  • Set Build Active Architectures Only to No
  • Apply the same settings to the Widget target

After that, the widget works correctly both in the simulator and on my test devices.

+4
source

add

 self.preferredContentSize = CGSizeMake(320, 60); 

to

 -(void)viewdidload{} 

in viewcontroller.m extension.

This method solved my problem.

I hope this also helps u.

0
source

Source: https://habr.com/ru/post/977193/


All Articles