title: sending data from iOS to Apple Watch in swift
body: <p>In my app, when I run it in simulator, the data is being transferred to watch app. The data includes four <code>UILabels</code> and one <code>UIImageView</code>. But when I run it on a real iPhone, the data is being transferred except the <code>UIImageView</code>. Can anybody help me?</p>
  
  <p><a href="https://i.stack.imgur.com/beLZz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/beLZz.png" alt="screenshot for my watch apple simulator"></a></p>
  
  <p>Source code for my iOS app is:</p>
  
  <pre><code>func saveImageToFolder()
  {
  
      let imageData:NSData = 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 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 to Database!", 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
                          {
  
                             // self.ticketDataArray = NSMutableArray()
                              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>
  
  <p>my watch code is</p>
  
  <pre><code>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>