Last active
August 29, 2015 14:10
-
-
Save hansott/e26ef1303dd703e0210d to your computer and use it in GitHub Desktop.
PebbleConnector
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
import Foundation | |
public class PebbleConnector : NSObject, PBPebbleCentralDelegate, PBWatchDelegate { | |
public class var sharedInstance: PebbleConnector { | |
struct Singleton { | |
static let instance = PebbleConnector() | |
} | |
return Singleton.instance | |
} | |
let central = PBPebbleCentral.defaultCentral() | |
override init() { | |
super.init() | |
let uuid = NSMutableData(length: 16)! | |
NSUUID(UUIDString: "Insert your Pebble app UUID here")!.getUUIDBytes(UnsafeMutablePointer(uuid.mutableBytes)) | |
central.appUUID = uuid | |
central.delegate = self | |
} | |
public func launch() { | |
for w in central.connectedWatches { | |
launchPebbleApp(w as PBWatch) | |
} | |
} | |
func launchPebbleApp(watch: PBWatch!) { | |
watch.appMessagesLaunch({ (watch: PBWatch!, error: NSError!) -> Void in | |
if (error != nil) { | |
NSLog(":(") | |
} else { | |
NSLog(":)") | |
} | |
}, withUUID: PBPebbleCentral.defaultCentral().appUUID) | |
} | |
public func pebbleCentral(central: PBPebbleCentral!, watchDidConnect watch: PBWatch!, isNew: Bool) { | |
NSLog("Connected %@", watch) | |
PBPebbleCentral.defaultCentral().dataLoggingService.pollForData() | |
} | |
public func pebbleCentral(central: PBPebbleCentral!, watchDidDisconnect watch: PBWatch!) { | |
PBPebbleCentral.defaultCentral().dataLoggingService.pollForData() | |
NSLog("Gone %@", watch) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment