title: Branch.io: javascript detect whether mobile app is installed
body: <p>I have a web page where I want a particular link on a page to open our native mobile app if the app is installed, and if not, do what it is currently doing (which submits a form).  </p>
  
  <p>Note: I think this is different than a smart banner - I don't want the banner on this page.  I just want the normal app flow if there is no mobile app.</p>
  
  <p>I have integrated <code>branch-sdk</code> in the web page and in my ios app.  I have successfully set up a deep link from the web page to the iOS app (code not shown), but I am not getting results I expect when sniffing for whether the app is installed.</p>
  
  <p>Here's the code in the <code>&lt;head&gt;</code> of my webpage:</p>
  
  <pre><code>    branch.init('MY_KEY', null, function(err, data) {
          console.log('init...');
          console.dir(data);
      });
      branch.setIdentity('test-user', function(err, data) {
          console.log('identity...');
          console.dir(data);
      });
      branch.data(function(err, data) {
          console.log('data...');
          console.dir(data);
      })
  </code></pre>
  
  <p>Here's my code in <code>application(_:didFinishLaunchingWithOptions:)</code> in the iOS side:</p>
  
  <pre><code>    //Initialize Branch
      if let branch = Branch.getInstance() {
          branch.setDebug()
          branch.initSession(launchOptions: launchOptions, andRegisterDeepLinkHandler: { params, error in
              if let params = params, error == nil {
                  // params are the deep linked params associated with the link that the user clicked -&gt; was re-directed to this app
                  // params will be empty if no data found
                  // ... insert custom logic here ...
                  print("params: %@", params.description)
              }
          })
          branch.setIdentity("test-user")
      } else {
          readerLog.error("failed to initialize branch")
      }
  </code></pre>
  
  <p>Every time I load the webpage (even after loading it, and following the deep link), I get the following as output in the console.  Note that <code>+isfirstsession</code> is true, and the <code>hasApp</code> property is <code>null</code>:</p>
  
  <pre><code>[Log] init... (localhost, line 18)
  [Log] Object (localhost, line 20)
      data: "{\"+is_first_session\":true,\"+clicked_branch_link\":false}"
      data_parsed: {+is_first_session: true, +clicked_branch_link: false}
      has_app: null
      identity: null
      referring_identity: null
      referring_link: null
  
  [Log] identity... (localhost, line 23)
  [Log] Object (localhost, line 25)
      identity_id: "352945822373397525"
      link: "https://nlfd.app.link/?%24identity_id=352945822373397525"
      link_click_id: "352947632809063724"
      referring_data: "{\"$one_time_use\":false,\"+click_timestamp\":1485387510,\"_branch_match_id\":\"352945819276765390\",\"_t\":\"352945819276765390\",\"referrer\":\"link_clic…"
      referring_data_parsed: Object
      session_id: "352945822337503746"
  
  [Log] data... (localhost, line 28)
  [Log] Object (localhost, line 30)
      data: "{\"+is_first_session\":true,\"+clicked_branch_link\":false}"
      data_parsed: null
      has_app: null
      identity: null
      referring_identity: null
      referring_link: null
  </code></pre>
  
  <p>What am I doing wrong?  I was hoping I could just look at the <code>has_app</code> property after init or after setting the identity.  Is it incorrect to assume that <code>has_app</code> would return true in this case?  Is there a more appropriate way to do what I want to do?</p>