title: get ApplicationContext on react-native
body: <p>I have a watchKit app connected with a react-native iOS app with <a href="https://github.com/mtford90/react-native-watch-connectivity" rel="nofollow noreferrer">react-native-watch-connectivity</a>.</p>
  
  <p>I want to use the applicationContext to communicate between the devices.</p>
  
  <p>From react-native, I use <code>watch.updateApplicationContext({ dataFromRN: "data" })</code> to define it and I can get it in iWatch side.</p>
  
  <p><strong>But when I use <code>updateApplicationContext(["data":"data"])</code> in iWatch side, an updated context event is catch by react-native but the data is not updated.</strong></p>
  
  <pre><code>// iWatch
  try session?.updateApplicationContext(["dataFromWatch":"data"])
  print(session?.applicationContext ?? "")
  </code></pre>
  
  <blockquote>
    <p>["dataFromWatch": "data"]</p>
  </blockquote>
  
  <p>but in react-native, I have the following output for this event:</p>
  
  <pre><code>// react-native iOS
  receiveApplicationContext(err, applicationContext) {
    console.log("receiveApplicationContext()", applicationContext)
  </code></pre>
  
  <blockquote>
    <p>receiveApplicationContext() {dataFromRN: "data"}</p>
  </blockquote>
  
  <p>dataFromRN is a previous applicationContext defined from react-native side.</p>
  
  <p>Event if react-native catch an event, the applicationContext is not updated.</p>
  
  <p>(react-native-watch-connectivity has react version defined to <strong>15.4.2</strong> but I'm using react <strong>16.2.0</strong>. Is something can be breaking changed between this versions ?)</p>
  
  <p>I guess I have to update something in react-native-watch-connectivity, but I would like to know where.</p>
  
  <p>If you have any element to fix this issue...</p>
  
  <p>Thx</p>
  
  <p>iOS side (with react-native)</p>
  
  <pre><code>import React, { Component } from "react";
  import {
    Platform,
    StyleSheet,
    Text,
    View,
    ScrollView,
    AsyncStorage,
    TouchableHighlight
  } from "react-native";
  import * as watch from "react-native-watch-connectivity";
  
  type Props = {};
  export default class App extends Component&lt;Props&gt; {
    constructor(props) {
      super(props);
      this.state = { match: [] };
      this.receiveUserInfo = this.receiveUserInfo.bind(this);
      this.subscribeToApplicationContext = this.subscribeToApplicationContext.bind(this);
      this.subscribeToWatchEvents = this.subscribeToWatchEvents.bind(this);
    }
  
    receiveUserInfo(err, userInfo) {
      if (!err) {
        if (userInfo.currentMatch !== undefined) {
          console.log("receiveUserInfo()", userInfo);
        }
      }
    }
  
    receiveApplicationContext(err, applicationContext) {
      if (!err) {
        console.log("receiveApplicationContext()", applicationContext);
          watch.getApplicationContext().then(context =&gt; {
          console.log("getApplicationContext()", context);
        });
      }
    }
  
    subscribeToWatchEvents() {
      this.subscriptions = [
        watch.subscribeToUserInfo(this.receiveUserInfo),
        watch.subscribeToApplicationContext(this.receiveApplicationContext)
      ];
    }
  
    componentDidMount() {
      this.subscribeToWatchEvents();
    }
  
    componentWillUnmount() {}
  
    render() {
      return (
        &lt;View/&gt;
      );
    }
  }
  </code></pre>
  
  <p>iWatch side (swift)</p>
  
  <pre><code>import WatchKit
  import Foundation
  import WatchConnectivity
  
  class MainController: WKInterfaceController, WCSessionDelegate {
  
    var session: WCSession?
  
    override func awake(withContext context: Any?) {
      super.awake(withContext: context)
      if WCSession.isSupported() {
        self.session = WCSession.default
        self.session?.delegate = self
        self.session?.activate()
      }
    }
  
    func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
      print("activationDidCompleteWith", activationState)
    }
  
    func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
      print("didReceiveApplicationContext", applicationContext)
    }
  
    func sendUserInfo() {
      session?.transferUserInfo(["data":"data"])
      do {
        try session?.updateApplicationContext(["data":"data"])
      } catch {
        print("updateApplicationContext error")
      }
      print(session?.applicationContext ?? "")
    }
  
    @IBAction func point() {
      sendUserInfo()
    }
  
  }
  </code></pre>