Skip to content

Instantly share code, notes, and snippets.

@RommelTJ
Created April 20, 2015 19:07
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 RommelTJ/5012007d59ce7e345883 to your computer and use it in GitHub Desktop.
Save RommelTJ/5012007d59ce7e345883 to your computer and use it in GitHub Desktop.
Sample Dynamic Notification for Apple Watch
//
// 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