iOS Tutorial Background Fetch (Downloads)

MarcoRome

Expert
Licensed User
if you @Erel or your team or other colleagues can try the attached code in post #38 and tell me if they work.
He doesnt work here. Tested on 2 iphone ( iphone 6s with 11.4 and xPhone )
Perhaps because it is compiled with the B4i 5.0 version ?
Maybe because some part of the code is wrong ?
I dont know but anyway it doesnt work.
Thank you again all
Marco
 

MarcoRome

Expert
Licensed User
I'm checking it. If you have a local Mac then you can monitor the logs and you will see that the OS mostly doesn't allow any app to start in the background. I'm still monitoring it to see if it will eventually run.
Hi @Erel thank you for your time

I tried with B4iLogger, but as you can see from the movie, after almost an hour no event ( Application_FetchDownload ) is Raised
 

Erel

Administrator
Staff member
Licensed User
After testing it for 24 hours I can say that it works properly.

I've created a simple app that counts the number of times FetchDownload is called:

B4X:
'app start
If File.Exists(File.DirDocuments, "1.txt") = False Then
       File.WriteString(File.DirDocuments, "1.txt", 0)
   End If

Sub Application_Active
   Page1.Title = "Value: " & File.ReadString(File.DirDocuments, "1.txt")
  
End Sub

Private Sub Application_FetchDownload
   Log("FetchDownload")
   File.WriteString(File.DirDocuments, "1.txt", File.ReadString(File.DirDocuments, "1.txt") + 1)
   Dim no As NativeObject = App
   no = no.GetField("delegate")
   no.RunMethod("completeFetch:", Array(0))
End Sub
Monitoring the system logs shows that many apps try to start in the background and the OS gives a score to each one. Only Apple knows how the score is calculated. I assumed that the app should be used from time to time so I started every couple of hours.
The first FetchDownload event happened after about 12 hours. It was raised another 11 times in the following 12 hours.

System logs:


Don't use iReleaseLogger with fetch download as it can cause the process to fail to start.
Don't show a notification. Maybe the OS doesn't like.

It is probably not relevant however I used an app that also implements push notifications.
 

MarcoRome

Expert
Licensed User
The first FetchDownload event happened after about 12 hours. It was raised another 11 times in the following 12 hours.
I would say to forget it is not very reliable.
@Erel thank you for your support and your time it's really exceptional.
Marco
 

Sasuke Sama

Active Member
Licensed User
Using this can i download larg files ( about 150 MB ) in the background ? And start the download from within the app
In other words can i make a download manager app with it?
 
Top