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):
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.
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