title: How to put the application in the background and return to put in the foreground (watchOS and iOS)?
body: <p>I am making an application for watchOS which aims to receive some notifications, and the device which sends these notifications is the iPhone.</p>
  
  <p>I have managed to make the communication between the Apple Watch and the iPhone and the iPhone already sends messages to the Apple Watch and the Apple Watch also already sends messages to the iPhone. I did not use the <code>WatchNotification</code> tool.</p>
  
  <p>What's happening is the following, when I run the application, it automatically opens in the Apple Watch, and what I want is that the application stays running at the background. When I press a button in the iPhone, a text is sent to the Apple Watch, and only then (when the Apple Watch receives the text) the application opens normally.</p>
  
  <p>I'll appreciate any help.</p>
  
  <p><strong>iPhone Code</strong></p>
  
  <pre><code>import UIKit
  import WatchConnectivity
  
  class ViewController: UIViewController,WCSessionDelegate {
  
  var iphoneNotification = "Deseja renovar o seu seguro automovel?"
  let session = WCSession.defaultSession()
  @IBOutlet weak var lblNotification: UILabel!
  
  override func viewDidLoad() {
      initSession()
      super.viewDidLoad()
      // Do any additional setup after loading the view, typically from a nib.
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  
  @IBAction func ActionSentNotification(sender: AnyObject) {
      let msg = ["NotificationSentforIphone" : iphoneNotification]
  
      session.sendMessage(msg, replyHandler: {(replay) -&gt; Void in }) { (error) -&gt; Void in
  
  
  
      }
  }
  
  func session(session: WCSession, didReceiveMessage message: [String : AnyObject])
  
  {
  
      let msg = message["NotificationSentforWatch"] as! String
      lblNotification.text = "\(msg)"
  
  
  }
  
  func initSession()
  
  {
  
      session.delegate = self
  
      session.activateSession()
  
  
  
  
  }
  }
  </code></pre>
  
  <p><strong>Watch Code</strong></p>
  
  <pre><code>import WatchKit
  import Foundation
  import WatchConnectivity
  
  class InterfaceController: WKInterfaceController,WCSessionDelegate {
  
  @IBOutlet var Notification: WKInterfaceLabel!
  var watchNotification = "ok"
  let session = WCSession.defaultSession()
  //@IBOutlet var lblNotification: WKInterfaceLabel!
  
  override func awakeWithContext(context: AnyObject?) {
      super.awakeWithContext(context)
  
      // Configure interface objects here.
  }
  
  override func willActivate() {
      // This method is called when watch view controller is about to be visible to user
      initSession()
      super.willActivate()
  }
  
  func session(session: WCSession, didReceiveMessage message: [String : AnyObject])
  
  {
  
      let msg = message["NotificationSentforIphone"] as! String
      Notification.setText("\(msg)")
      //lblNotification.setText("Notification:\(msg)")
  
  }
  @IBAction func ActionSentNotificationforIphone()
  {
      let msg = ["NotificationSentforWatch" : watchNotification]
  
      session.sendMessage(msg, replyHandler: {(replay) -&gt; Void in }) { (error) -&gt; Void in
  
  
  
      }
  
  }
  override func didDeactivate() {
      // This method is called when watch view controller is no longer visible
      super.didDeactivate()
  }
  
  func initSession()
  
  {
  
      session.delegate=self
  
      session.activateSession()
  
  
  
  }
  
  
  
  }
  </code></pre>