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

pierrem

Member
Licensed User
Longtime User
Hi,

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
:)
 

pierrem

Member
Licensed User
Longtime 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
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime 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):
B4X:
Sub Application_Background
   Dim nativeMe As NativeObject = Me
   nativeMe.RunMethod("moreBackgroundTime", Null)
End Sub

#If OBJC
- (void)moreBackgroundTime {
   UIApplication* app = [UIApplication sharedApplication];
   UIBackgroundTaskIdentifier bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
     [app endBackgroundTask: bgTask];
   }];
}
#end if
 
Upvote 0

omidaghakhani1368

Well-Known Member
Licensed User
Longtime 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):
B4X:
Sub Application_Background
   Dim nativeMe As NativeObject = Me
   nativeMe.RunMethod("moreBackgroundTime", Null)
End Sub

#If OBJC
- (void)moreBackgroundTime {
   UIApplication* app = [UIApplication sharedApplication];
   UIBackgroundTaskIdentifier bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
     [app endBackgroundTask: bgTask];
   }];
}
#end if
Hi Erel.This code looklike service,isn't?
 
Upvote 0
Top