1. #1
    Sencha User
    Join Date
    Aug 2009
    Posts
    96
    Vote Rating
    1
    r4nd7263 is on a distinguished road

      0  

    Default Checking if running in PhoneGap or Mobile Web Browser

    Checking if running in PhoneGap or Mobile Web Browser


    How do I check if the app is running in PhoneGap (or as native app) vs Mobile web browser (i.e. Safari)?

    For example in this pseudocode

    Code:
    if (runningNatively) {
        enable camera-related UI
    } else {
        disable camera-related UI
    }

    The reason I am asking is because I have a ST web app working and it's in production. I used the same code to build a sample iPhone app, but now I need to add native device functions, such as camera and push notification.

    I am debating whether I should use the same code base (modify one copy), but add checks at certain points in the app to integrate native phone functions, or should I make a copy, and maintain two separate code bases (Web app vs Native app).

    [EDIT] I guess I could always hardcode a global constant in index.html, then I maintain two index.html but one app.js. Still I'd like to know what others think.

  2. #2
    Touch Premium Member
    Join Date
    Aug 2010
    Posts
    195
    Vote Rating
    2
    hitman01 is on a distinguished road

      0  

    Default


    I'm also interested.
    http://www.dev4.life - Software Development Blog

  3. #3
    Sencha User
    Join Date
    Jul 2010
    Location
    Switzerland
    Posts
    78
    Vote Rating
    0
    fx-mike is on a distinguished road

      0  

    Default


    I use this in my app.js

    Code:
    phoneGapAvailable: function() {
      return typeof(PhoneGap) != 'undefined';
    }
    It has worked so far, but I haven't tested it thoroughly yet. Maybe someone has an alternative solution?

Thread Participants: 2