     
     // 2
     func reflashTinker() {
+
+        if !self.device!.connected {
+            TSMessage.showNotificationWithTitle("Device offline", subtitle: "Device must be online to be flashed", type: .Error)
+            return
+        }
+        
+        func flashTinkerBinary(binaryFilename : String?)
+        {
+            let bundle = NSBundle.mainBundle()
+            let path = bundle.pathForResource(binaryFilename, ofType: "bin")
+            let binary = NSData(contentsOfURL: NSURL(fileURLWithPath: path!))
+            let filesDict = ["tinker.bin" : binary!]
+            self.device!.flashFiles(filesDict, completion: { (error:NSError?) -> Void in
+                if let e=error
+                {
+                    TSMessage.showNotificationWithTitle("Flashing error", subtitle: "Error flashing device: \(e.localizedDescription)", type: .Error)
+                }
+                else
+                {
+                    TSMessage.showNotificationWithTitle("Flashing successful", subtitle: "Please wait while your device is being flashed with Tinker firmware...", type: .Success)
+                }
+            })
+        }
         
         
         switch (self.device!.type)

    
    @IBAction func actionButtonTapped(sender: UIButton) {
        // heading
        let dialog = ZAlertView(title: "More Actions", message: nil, alertType: .MultipleChoice)
        


                else
                {
                    TSMessage.showNotificationWithTitle("Flashing successful", subtitle: "Please wait while your device is being flashed with Tinker firmware...", type: .Success)
                }
            })
            
        case .Photon:
            Mixpanel.sharedInstance().track("Tinker: Reflash Tinker", properties: ["device":"Photon"])
            flashTinkerBinary("photon-tinker")
            
        case .Electron:
            Mixpanel.sharedInstance().track("Tinker: Reflash Tinker", properties: ["device":"Electron"])
            
            let dialog = ZAlertView(title: "Flashing Electron", message: "Flashing Tinker to Electron via cellular will consume data from your data plan, are you sure you want to continue?", isOkButtonLeft: true, okButtonText: "No", cancelButtonText: "Yes",
                                    okButtonHandler: { alertView in
                                        alertView.dismiss()
                                        
                },
                                    cancelButtonHandler: { alertView in
                                        alertView.dismiss()
                                        flashTinkerBinary("electron-tinker")
                                        
                }
            )
            
            
            
            dialog.show()
            
        default:
            TSMessage.showNotificationWithTitle("Reflash Tinker", subtitle: "Cannot flash Tinker to a non-Particle device", type: .Warning)
            
            
        }
