title: Send UILabels and UIImage to real apple watch from Iphone in swift
body: <p>I want to send <code>UILabels</code> and <code>UIImage</code> data to my watch app from ios app.  I am getting it in simulator when i click "sendtowatch" button. But when i run it in real devices, only the label is shown not the image.</p>
  
  <p>Source code for <strong>watch:</strong></p>
  
  <pre><code>    class InterfaceController: WKInterfaceController, WCSessionDelegate {
  
      var session: WCSession!
  
      var MessageData = NSMutableDictionary()
  
      @IBOutlet var watch_displayImage: WKInterfaceImage!
      @IBOutlet var watch_ticket_category: WKInterfaceLabel!
      @IBOutlet var watch_ticketType: WKInterfaceLabel!
      @IBOutlet var watch_ticketTime: WKInterfaceLabel!
      @IBOutlet var watch_ticketDate: WKInterfaceLabel!
  
      override func awakeWithContext(context: AnyObject?) {
          super.awakeWithContext(context)
  
          if WCSession.isSupported()
          {
  
              session = WCSession.defaultSession()
              session.delegate = self
              session.activateSession()
  
          }
  
      }
  
      override func willActivate() {
          // This method is called when watch view controller is about to be visible to user
          super.willActivate()
  
  
      }
  
  
      func session(session: WCSession, didReceiveMessage message: [String : AnyObject], replyHandler: ([String : AnyObject]) -&gt; Void)
      {
  
          print(message.values)
  
          MessageData = NSMutableDictionary(object: message, forKey: "data")
          print("Message data---",MessageData)
  
          watch_ticket_category.setText("\(MessageData["data"]!["Watchdat"]!!["ticket_category"] as! String)")
          watch_displayImage.setImage(UIImage(named: MessageData["data"]!["Watchdat"]!!["imagePath"] as! String))
          watch_ticketType.setText("\(MessageData["data"]!["Watchdat"]!!["ticket_type"] as! String)")
          watch_ticketTime.setText("\(MessageData["data"]!["Watchdat"]!!["time"] as! String)")
          watch_ticketDate.setText("\(MessageData["data"]!["Watchdat"]!!["date"] as! String)")
  
  
     }
  </code></pre>
  
  <p>Source code for <strong>IOS app:</strong> </p>
  
  <pre><code>   class TicketDetailViewController: UIViewController, WCSessionDelegate {
    let dic1  = NSMutableDictionary()
      var defaults = NSUserDefaults()
      var databasePath = NSString()
      var holding_Ticket_category: String = ""
      var holding_Image: UIImage?
      var hold_ticketName: String = ""
      var hold_ticketDate: String = ""
      var hold_ticketTime: String = ""
      var session: WCSession!
      var imageData: NSData!
  
      @IBOutlet weak var ticket_grey: UIImageView!
      @IBOutlet weak var cropped_frame: UIImageView!
      @IBOutlet weak var display_image: UIImageView!
      @IBOutlet weak var ticket_type_name: UILabel!
      @IBOutlet weak var ticket_date: UILabel!
      @IBOutlet weak var ticket_time: UILabel!
      @IBOutlet weak var ticket_category: UILabel!
  
  
      override func viewDidLoad()
      {
          super.viewDidLoad()
          if WCSession.isSupported(){
              self.session  = WCSession.defaultSession()
              self.session.delegate = self
              self.session.activateSession()
          }
  
          defaults = NSUserDefaults.standardUserDefaults()
  
          display_image.image = self.holding_Image
          ticket_type_name.text = hold_ticketName
          ticket_date.text = hold_ticketDate
          ticket_time.text = hold_ticketTime
          ticket_category.text = holding_Ticket_category
  
          let filemgr =  NSFileManager.defaultManager()
          let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
          let docsDir = dirPaths[0]
          var ticketDB: FMDatabase
  
          databasePath = (docsDir as NSString).stringByAppendingPathComponent("ticket_Pass.sqlite")
  
  
          if !filemgr.fileExistsAtPath(databasePath as String)
          {
  
              ticketDB = FMDatabase(path: databasePath as String)
              if ticketDB.open()
              {
  
                  let sql_stmt = "CREATE TABLE IF NOT EXISTS TICKET (ID INTEGER PRIMARY KEY AUTOINCREMENT, IMAGEPATH TEXT, IMAGENAME TEXT, TICKET_CATEGORY TEXT, TICKET_TYPE TEXT, DATE TEXT, TIME TEXT)"
                  if !ticketDB.executeStatements(sql_stmt)
                  {
                      print("Error: \(ticketDB.lastErrorMessage())")
                  }
                  ticketDB.close()
              } else
              {
                   print("Error: \(ticketDB.lastErrorMessage())")
              }
          }else{
              ticketDB = FMDatabase(path: databasePath as String)
              if ticketDB.open()
              {
  
                  let sql_stmt = "CREATE TABLE IF NOT EXISTS TICKET (ID INTEGER PRIMARY KEY AUTOINCREMENT, IMAGEPATH TEXT, IMAGENAME TEXT, TICKET_CATEGORY TEXT, TICKET_TYPE TEXT, DATE TEXT, TIME TEXT)"
                  if !ticketDB.executeStatements(sql_stmt)
                  {
                      print("Error: \(ticketDB.lastErrorMessage())")
                  }
                  ticketDB.close()
              } else
              {
  
                  print("Error: \(ticketDB.lastErrorMessage())")
              }
  
          }
      }
  
      func saveImageToFolder()
      {
  
          imageData = UIImagePNGRepresentation(holding_Image!)!
          let imageName = "image_\(NSDate.timeIntervalSinceReferenceDate()).png"
          let imagePath = (self.getDocumentsDirectory() as NSString).stringByAppendingPathComponent(imageName)
          print("imagePath:- \(imagePath)")
  
          imageData.writeToFile(imagePath, atomically: true)
          NSUserDefaults.standardUserDefaults().setObject(imagePath, forKey: "ImagePath")
          NSUserDefaults.standardUserDefaults().setObject(imageData, forKey: "ImageData")
          NSUserDefaults.standardUserDefaults().setObject(imageName, forKey: "ImageName")
          NSUserDefaults.standardUserDefaults().synchronize()
  
      }
  
      func getDocumentsDirectory() -&gt; String{
          var paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
          let documentsPath = paths[0]
          print("document path:- \(documentsPath)")
          return documentsPath
  
      }
  
    @IBAction func addTickets(sender: UIButton)
    {
  
          let ticketDB = FMDatabase(path: databasePath as String)
          if ticketDB.open()
          {
                  //self.saveImageToFolder()
                  let insertSQL = "INSERT INTO TICKET (imagePath, imageName, ticket_category, ticket_type, date, time) VALUES ('\(NSUserDefaults.standardUserDefaults().objectForKey("ImagePath")!)', '\(NSUserDefaults.standardUserDefaults().objectForKey("ImageName")!)', '\(ticket_category.text!)', '\(ticket_type_name.text!)', '\(ticket_date.text!)', '\(ticket_time.text!)')"
  
                  let result = ticketDB.executeUpdate(insertSQL,withArgumentsInArray: nil)
  
                  if !result
                  {
  
                      print("Error: \(ticketDB.lastErrorMessage())")
  
                  } else
                  {
  
                      let alt = PMAlertController(title: "Success!", description: "Your data is saved to Database!", image: UIImage(named: ""), style: .Alert)
  
                      alt.addAction(PMAlertAction(title: "OK!", style: .Default, action: { (ACTION) -&gt; Void in
  
                      self.navigationController?.popToRootViewControllerAnimated(true)
  
                      }))
  
                      self.presentViewController(alt, animated: true, completion: nil)
                      print(databasePath)
  
                 }
          }
      }
  
  
      @IBAction func deleteTickets(sender: UIButton) {
          let alt = PMAlertController(title: "Delete Ticket Details!", description: "Are you sure?", image: UIImage(named: ""), style: .Alert)
  
          alt.addAction(PMAlertAction(title: "Cancel", style: PMAlertActionStyle.Default, action: { (ACTION) -&gt; Void in
  
              self.dismissViewControllerAnimated(true, completion: nil)
  
          }))
          alt.addAction(PMAlertAction(title: "OK", style: PMAlertActionStyle.Default, action: { (ACTION) -&gt; Void in
  
              self.navigationController?.popToRootViewControllerAnimated(true)
          }))
          self.presentViewController(alt, animated: true, completion: nil)
      }
  
  
      @IBAction func sendToWatch(sender: AnyObject)
      {
  
          let ticketDB = FMDatabase(path: databasePath as String)
          if ticketDB.open()
          {
              self.saveImageToFolder()
              let insertSQL = "INSERT INTO TICKET (imagePath, imageName, ticket_category, ticket_type, date, time) VALUES ('\(NSUserDefaults.standardUserDefaults().objectForKey("ImagePath")!)', '\(NSUserDefaults.standardUserDefaults().objectForKey("ImageName")!)', '\(ticket_category.text!)', '\(ticket_type_name.text!)', '\(ticket_date.text!)', '\(ticket_time.text!)')"
  
              let result = ticketDB.executeUpdate(insertSQL,withArgumentsInArray: nil)
  
              if !result
              {
  
                  print("Error: \(ticketDB.lastErrorMessage())")
  
              } else
              {
  
                  let alt = PMAlertController(title: "Success!", description: "Your data is saved!", image: UIImage(named: ""), style: .Alert)
  
                  alt.addAction(PMAlertAction(title: "OK!", style: .Default, action:
                  { (ACTION) -&gt; Void in
  
  
                          let ticketDB = FMDatabase(path: self.databasePath as String)
                          if ticketDB.open()
                          {
  
  //                            let querySQL = "SELECT * FROM TICKET ORDER BY ID DESC LIMIT 1"
                               let querySQL = "SELECT * FROM TICKET "
  
                              let result: FMResultSet? = ticketDB.executeQuery(querySQL, withArgumentsInArray: nil)
  
                              if let result = result
                              {
  
                                  let ticketDataArray:NSMutableArray = NSMutableArray()
                                  while result.next()
                                  {
  
                                      self.dic1.setObject(result.stringForColumn("imagePath"), forKey: "imagePath")
                                      self.dic1.setObject(result.stringForColumn("imageName"), forKey: "imageName")
                                      self.dic1.setObject(result.stringForColumn("ticket_category"), forKey: "ticket_category")
                                      self.dic1.setObject(result.stringForColumn("ticket_type"), forKey: "ticket_type")
                                      self.dic1.setObject(result.stringForColumn("date"), forKey: "date")
                                      self.dic1.setObject(result.stringForColumn("time"), forKey: "time")
  
                                      ticketDataArray.addObject(self.dic1)
  
                                  }
                                  print("ticketDataArray :  \(self.dic1)")
                              }else
                              {
                                  print("Error: \(ticketDB.lastErrorMessage())")
  
                              }
  
                            ticketDB.close()
  
                          }
                      self.navigationController?.popToRootViewControllerAnimated(true)
                          if WCSession.defaultSession().reachable
                          {
                              let dict = ["Watchdat":self.dic1]
  
                              self.session.sendMessage(dict, replyHandler: { (replayDic: [String:AnyObject]) in
                                  print("success!")
                                  }, errorHandler: { (error:NSError) in
                                      print("error")
                              })
                          }
  
                  }))
  
                  self.presentViewController(alt, animated: true, completion: nil)
                  print(databasePath)
  
              }
          }
  </code></pre>