iOS Question [SOLVED] How to job.postString before app goes to background

Discussion in 'iOS Questions' started by pierrem, Jan 25, 2015.

  1. pierrem

    pierrem Member Licensed User


    I would like to send to an http server when the user has pressed the Back Button.

    If i send the request in the Application_Background, the app seems to be 'backgrounded' before the request has been sent.
    (I dont see the request on the http server ...)

    Is it a way to workaround ?

    I had imagined to show an "OK" button, not enabled, in the Application_Background sub ... and to enable it when the jobDone is fired ...
    Not sure Apple will agree on this
    (and not sure it works ... no tested at all)

    FYI : In B4A, I started a service juste for that, and kill the service when jobDone is fired ... Doesn't sound possible with iOS.

    Thanks in advance for yours advices
  2. Erel

    Erel Administrator Staff Member Licensed User

    Have you tried it in release mode or debug mode?
  3. pierrem

    pierrem Member Licensed User

    Hi Erel,

    Just retested this morning.

    It's OK in debug mode, http server receives the post from the app

    It's NOT OK in release mode, http serveur doesn't receive the post from the app.

    Hope it helps
  4. Erel

    Erel Administrator Staff Member Licensed User

    Normally iOS pauses (and later kills) the process after the Background event. You can ask the system to provide you more time to finish the task. The required code is added to the debugged app automatically to allow the debugger to stay connected even if the app has moved to the background.

    Add this code and call it to allow your app to keep running in the background for a short time (should be enough for the request):
    Sub Application_Background
    Dim nativeMe As NativeObject = Me
    End Sub

    #If OBJC
    - (void)moreBackgroundTime {
       UIApplication* app = [UIApplication sharedApplication];
       UIBackgroundTaskIdentifier bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
         [app endBackgroundTask: bgTask];
    #end if
    inakigarm likes this.
  5. pierrem

    pierrem Member Licensed User

    Works fine

  6. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    Hi Erel.This code looklike service,isn't?
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice