Have successfully built my first IOS app using swift. But I do have a question concerning “get device” function. Is there a way to tell whether or not a device is active (turned on) programmatically? I noticed when clicking on “devices” using “Particle Build” there is a color coded dot that signifies when a particular device is active or not. I would like to replicate this if possible.
Thanks Moors, I see that in the “get” response there is a bool that indicates whether or not the device is connected to the cloud.
To save me some time, and it’s not too much of a problem, would you by chance have the snippet of swift sample code that would accomplish this check? I would like to incorporate it into the “get device” function? If not, I’ll try to figure it out.
var myPhoton : SparkDevice?
SparkCloud.sharedInstance().getDevices { (sparkDevices:[AnyObject]!, error:NSError!) -> Void in
if let e = error {
println("Check your internet connectivity")
}
else {
if let devices = sparkDevices as? [SparkDevice] {
for device in devices {
if device.connected == true {
//do stuff here for connected devices
}
else {
// do stuff for non-connected devices?
}
}
}
}
}
This is a total, random guess, with a high chance of it not working… Just sayin’
Lol you hit a home run, it works just a fine. For some reason I was thinking I had to write some special API call but actually it was nothing more than setting a property in the cloud class, as you so graciously pointed out. Thank you for taking time to assist😄