iOS Question Lack of services in ios


Well-Known Member
Licensed User
Longtime User
I wrote an application for Android and used services there for compressing photos and uploading photos to the server.
Compressing a photo seems like a long enough time, especially if it is 100 photos, so I implemented it in the service so that at this moment the user can minimize the application and do other things. Can I do something like this in ios?
    For i=0 To uris.Size-1
        Dim FileSize=100 As Int
        Do While File.Size(File.DirInternal,NumberFile&".jpg")>500000
            Out = File.OpenOutput(File.DirInternal,NumberFile&".jpg",False)
            Bitmap.WriteToStream(Out, FileSize, "JPEG")
Then I upload these photos to the server using web services (OkHttp). When sending 100 photos, this is also a rather lengthy process, so it was implemented using services. Can I do something like this in ios?


Well-Known Member
Licensed User
Longtime User
Create a regular class and implement your logic in it. But You won’t be able to run it in the background like a service. Your app need to be running while the class operates.
Upvote 0


B4X founder
Staff member
Licensed User
Longtime User
The best you can do is:
1. Ask the OS to give you more time.
2. Notify the user that the app needs to be visible in order to complete uploading data.

Example of requesting the OS to let your app complete the task. Test it in release mode and switch to the background after you click the button. You will see that it will run for about 30 seconds. This is a bit more than the few seconds that you will have without calling StartBackgroundTask.
Note that in debug mode, the debugger makes a similar request when the app moves to the background.
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private xui As XUI
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    App.RegisterUserNotifications(True, True, True)
End Sub

Sub Button1_Click
    Dim no As NativeObject = App
    Log("move to the background")
    Log($"Remaining time: $1.2{no.GetField("backgroundTimeRemaining").AsNumber}"$)
    App.ApplicationIconBadgeNumber = Min(1000, no.GetField("backgroundTimeRemaining").AsNumber + 100)
    Do While True
        App.ApplicationIconBadgeNumber = App.ApplicationIconBadgeNumber - 1
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
End Sub

Private Sub StartBackgroundTask
    Dim no As NativeObject = Me
    no.RunMethod("startBackgroundTask", Null)
End Sub

#if OBJC
- (void) startBackgroundTask {
 UIBackgroundTaskIdentifier bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
            [[UIApplication sharedApplication] endBackgroundTask:bgTask];
#End If
Upvote 0


Well-Known Member
Licensed User
Longtime User
Is there any way you can get iOS not to turn off the screen while the application is running?
In the Android, I did it with PhoneWakeState
Upvote 0