Created
April 20, 2015 19:07
-
-
Save RommelTJ/5012007d59ce7e345883 to your computer and use it in GitHub Desktop.
Sample Dynamic Notification for Apple Watch
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
// | |
// DynamicNotificationController.swift | |
// NotificationDemo | |
// | |
// Created by Rommel Rico on 4/20/15. | |
// Copyright (c) 2015 Rommel Rico. All rights reserved. | |
// | |
import WatchKit | |
import Foundation | |
class DynamicNotificationController: WKUserNotificationInterfaceController { | |
@IBOutlet weak var testLabel: WKInterfaceLabel! | |
override init() { | |
// Initialize variables here. | |
super.init() | |
// Configure interface objects here. | |
//testLabel.setText("You've been notified!") | |
} | |
override func willActivate() { | |
// This method is called when watch view controller is about to be visible to user | |
super.willActivate() | |
} | |
override func didDeactivate() { | |
// This method is called when watch view controller is no longer visible | |
super.didDeactivate() | |
} | |
override func didReceiveLocalNotification(localNotification: UILocalNotification, withCompletion completionHandler: ((WKUserNotificationInterfaceType) -> Void)) { | |
//TODO | |
} | |
override func didReceiveRemoteNotification(remoteNotification: [NSObject : AnyObject], withCompletion completionHandler: ((WKUserNotificationInterfaceType) -> Void)) { | |
//Get the aps dictionary from the payload. | |
let apsDictionary: NSDictionary = (remoteNotification["aps"] as? [NSObject: AnyObject])! | |
//Set the dynamic label | |
testLabel.setText("You've been notified!") | |
//Tell WatchKit to display the custom interface | |
completionHandler(WKUserNotificationInterfaceType.Custom) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment