0

I'm quite new to iOS and I hit 2 problems when writing a hello world Today extension for iOS8. I tried to create a simple today extension using the template and it works good.

However if I tried 1 of the following, the widget does not show up in Today app (there's only a title of my extension, but no body):

  1. Delete the "hello world" label coming with the template, and add 1 new label with "hello world 2"; I notice the constraints are also automatically deleted if I'm doing this.

  2. Uncheck "Use Auto Layout" in storyboard of today view controller, create a property of UILabel and link to the label in storyboard, then call setText on the label on viewDidLoad:

TodayViewController.m:

@interface TodayViewController () <NCWidgetProviding>

@property (nonatomic, weak) IBOutlet UILabel *cityLabel;

@end

@implementation TodayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self _updateTodayView];
}

- (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.
    [self _updateTodayView];

    // If an error is encountered, use NCUpdateResultFailed
    // If there's no update required, use NCUpdateResultNoData
    // If there's an update, use NCUpdateResultNewData

    completionHandler(NCUpdateResultNewData);
}

- (void) _updateTodayView {
    [[self cityLabel] setText:@"Hello World 3"];
}

@end

I've been developing on Windows for years and I'm ashamed to be blocked by this issue for a whole day.

My environment:
OS X Yosemite. Xcode 6.1

D_BOY
  • 11
  • 2
  • 1
    Compared to the template today extension, the only difference is that you're not using autolayout. Turn it back on and define some constraints that will force a certain height for the view. It could be that the today view requires autolayout to size the extensions. – Patrick Goley Dec 28 '14 at 15:02
  • thx, this could be the case. But I have to keep the "hello world" label coming with the template. What if my today extension does not need a label? I cannot delete it as it will cause the issue. – D_BOY Dec 29 '14 at 02:12

0 Answers0