Created
February 15, 2018 17:55
-
-
Save weswit-team/3fbd2fe45a675b883e96c9b06e72296a to your computer and use it in GitHub Desktop.
Implementation file NotificationController.m for the watchOS SDK tutorial.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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