Skip to content

Instantly share code, notes, and snippets.

@weswit-team
Created February 15, 2018 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weswit-team/3fbd2fe45a675b883e96c9b06e72296a to your computer and use it in GitHub Desktop.
Save weswit-team/3fbd2fe45a675b883e96c9b06e72296a to your computer and use it in GitHub Desktop.
Implementation file NotificationController.m for the watchOS SDK tutorial.
//
// NotificationController.m
// StockWatch Extension
//
#import <UserNotifications/UserNotifications.h>
#import "NotificationController.h"
@interface NotificationController ()
@end
@implementation NotificationController
- (instancetype) init {
if ((self = [super init])) {
// Nothing to do
}
return self;
}
- (void) willActivate {
[super willActivate];
}
- (void) didDeactivate {
[super didDeactivate];
}
- (void) didReceiveNotification:(UNNotification *)notification withCompletion:(void(^)(WKUserNotificationInterfaceType interface)) completionHandler {
// Retrieve the item's data
NSDictionary *item= notification.request.content.userInfo;
if (item) {
// Update the labels
self.nameLabel.text= [item objectForKey:@"stock_name"];
self.priceLabel.text= [item objectForKey:@"last_price"];
// Call the completion handler for custom (dynamic) notification
completionHandler(WKUserNotificationInterfaceTypeCustom);
} else {
// Call the completion handler for default (static) notification
completionHandler(WKUserNotificationInterfaceTypeDefault);
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment