ExtensionDelegate.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*****************************************************************************
  2. * ExtensionDelegate.swift
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Tobias Conradi <videolan # tobias-conradi.de>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. import WatchKit
  13. import WatchConnectivity
  14. import CoreData
  15. class ExtensionDelegate: NSObject, WKExtensionDelegate, WCSessionDelegate {
  16. func applicationDidFinishLaunching() {
  17. // Perform any final initialization of your application.
  18. WCSession.defaultSession().delegate = self;
  19. WCSession.defaultSession().activateSession()
  20. }
  21. func session(session: WCSession, didReceiveMessage message: [String : AnyObject], replyHandler: ([String : AnyObject]) -> Void) {
  22. let msg = VLCWatchMessage(dictionary: message)
  23. if msg.name == VLCWatchMessageNameNotification, let payloadDict = msg.payload as? [String : AnyObject] {
  24. if let name = payloadDict["name"] as? String {
  25. handleRemoteNotification(name, userInfo: payloadDict["userInfo"] as? [String : AnyObject])
  26. }
  27. }
  28. }
  29. func handleRemoteNotification(name:String, userInfo: [String: AnyObject]?) {
  30. NSNotificationCenter.defaultCenter().postNotificationName(name, object: self, userInfo: userInfo)
  31. }
  32. func session(session: WCSession, didReceiveFile file: WCSessionFile) {
  33. // TODO: copy db and send update notification
  34. }
  35. }