iOS Question Uploading files to the server in ios.

red30

Well-Known Member
Licensed User
Longtime User
Since there are no services in ios, I cannot upload files in the background. I am trying to find a solution to this problem. In this post, Erel gave an example of how you can extend the upload of files by 30 seconds, but I don't understand how it works and how I can use it ... Can you explain this in more detail?
I want to warn the user not to close the application while the upload is in progress, but if he nevertheless minimizes the application, can I show any message that the application needs to be urgently deployed, otherwise the upload will be interrupted. The server allows me to continue uploading if the pause between files is no more than 1 minute. That is, if at this moment I write a message for the user to urgently deploy the application, perhaps this will help to avoid a defective upload.
B4X:
    Dim templist As List
    templist=File.ListFiles(File.DirLibrary)
    For i=0 To templist.Size-1
        Dim j As HttpJob
        j.Initialize("", Me)
        Dim basicAuth As String = "XXX:YYY"
        Dim su As StringUtils
        Dim authInfo = su.EncodeBase64(basicAuth.GetBytes("UTF8")) As String
        Dim fd As MultipartFileData
        fd.Initialize
        fd.KeyName = "image"
        fd.Dir = File.DirLibrary
        fd.FileName = templist.Get(i)
        j.PostMultipart("XXX", CreateMap("image": templist.Get(i),"YYY": id), Array(fd))
        j.GetRequest.SetHeader("Authorization", "Basic "&authInfo)
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Log(j.GetString)
        Else
            Log("JobError: "&j.ErrorMessage)
        End If
    Next
After minimizing the application, how can I ask the user to deploy it?
 

Semen Matusovskiy

Well-Known Member
Licensed User
You can send local notification in Application_Background event.
BTW, IOS allows background uploads - https://developer.apple.com/documentation/foundation/nsurlsession

I am not sure, that it's possible to add new uploads in background (at least I was not able to do this). But it's exactly possible to start uploads in foreground state and background NSURLSession will finish a work (your app will receive JobDone event) even in suspended state.
 
Upvote 0
Top