lastConnectedWatch() of PBPebbleCentral returns always nil?

128 views Asked by At

I'm currently building a watchapp for Pebble which will have to communicate with one Swift app. I've implemented all the needed functions but every time I try to get the last connected Pebble from PBPebbleCentral I receive nil. This happens despite the fact that my Pebble is connected with the iPhone and I have PebbleKit and PebbleVendor correctly imported.
I'm using Pebble with firmware v2.7 and iPhone 5s running iOS 8.0.2. Further I have based my two apps on the weather-app example provided by Pebble.

 defaultCentral.delegate = self
 setTargetWatch(defaultCentral.lastConnectedWatch())
1

There are 1 answers

0
Gancheva On

I found my mistake! I used to receive nil from lastConnectedWatch() because I'd initialized defaultCentral incorrectly.

My old code was:

let defaultCentral: PBPebbleCentral = PBPebbleCentral()
defaultCentral.delegate = self
setTargetWatch(defaultCentral.lastConnectedWatch())

And the correct code is:

let defaultCentral: PBPebbleCentral = PBPebbleCentral.defaultCentral()
defaultCentral.delegate = self
setTargetWatch(defaultCentral.lastConnectedWatch())