Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Ajax calls start failing if my app is inactive; otherwise they work just fine on WiFi

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 667
    Answer it

    In my Phonegap based hybrid app: Ajax calls start failing if my app is inactive for say a couple of minutes. My connection is WiFi & what happens is ajax calls fail with status 0; but navigator.connection.type still shows WiFi. This happens only on iOS not on android.

     

    Then I i noticed if the user keeps clicking around the app (thus initiating ajax calls which actually keep failing with status 0), he is able to bring the app back on track after say 2 minutes (i.e. suddenly the ajax calls start working and post that the app works perfectly fine). Seeing this behavior I created a loop that executes on failure every 5 seconds until finally the app is able to connect i.e. successfully execute ajax call after 2 minutes. (This is not feasible since no user will wait for 2 minutes for the app to connect back)

    Other option i tried was to set the key UIRequiresPersistentWiFi in iOS property list file to YES (but this did not resolve the issue)

     

    I can also see the WiFi icon with full signal strength, Other Apps like facebook etc. work fine using the WiFi.

     

    I have really broken my head for the last couple of hours around this and i have no clue where and how to troubleshoot this. Any help is much appreciated. Thanks!

 1 Answer(s)

  • As an iOS developer I would suggest you to run all ajax related calls when app is in background state. If app is inactive or terminated by iOS then you can not run ajax call. For apps that support background execution, "applicationWillTerminate" method is generally not called when the user quits the app because the app simply moves to the background in that case. However, this method may be called in situations where the app is running in the background (not suspended) and the system needs to terminate it for some reason.

    If the app is killed or terminated then you can not do anything.

    Happy Coding!!

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: