iOS Question [SOLVED - NO DIFFERENCE!] "Wait For" operational differences between B4i and B4A?

Andris

Active Member
Licensed User
Longtime User
I'm converting an Android app to iOS. One irritating stumbling block is a difference in how B4i/iOS handles Wait For. Here's how I wait for completion of a file download from Firebase storage:
B4X:
    '...
    DownloadFromFirebase(filepath)
    Wait For storage_DownloadCompleted (ServerPath As String, Success As Boolean)
    '...

Sub DownloadFromFirebase(filepath)
    '...
    storage.DownloadFile(filepath,destdir,destname)
    '...
End Sub
In the case of B4A/Android, the Wait For acts as expected, interrupting program flow until storage_DownloadCompleted triggers. In B4i however, the Wait For is totally ignored with no wait. There must be a simple explanation here - can someone weigh in?
 
Last edited:
Solution
The fact that the Log after Wait For storage_DownloadCompleted is executed should mean that the download has in fact completed and the event raised to let the Wait For proceed. What is the value of the Success parameter? Put it in your Log statement.
Thanks Agraham, my lack of faith in my own stupidity has now been restored! Success was False, and ServerPath showed that I had a missing character in the file request. So of course it would come back False. Why I didn't examine these return values earlier is embarrassing. I'm sure it will now work just like B4A. Thanks again!!

Andris

Active Member
Licensed User
Longtime User
The behavior should be the same. Add log messages to better understand the flow.
So you're saying that the format of the Wait For is OK as I have it. Thanks for that. Is there any chance of different behavior because of B4i Debug mode?
 
Upvote 0

Andris

Active Member
Licensed User
Longtime User
Erel said:
The behavior should be the same. Add log messages to better understand the flow.
I added log messages in B4i as follows:
B4X:
    '...
    DownloadFromFirebase(filepath)
    Wait For storage_DownloadCompleted (ServerPath As String, Success As Boolean)
    Log("Wait For is over. Continuing with next statement ...")
    '...

Sub DownloadFromFirebase(filepath)
    '...
    storage.DownloadFile(filepath,destdir,destname)
    Log("Download started ...")
    '...
End Sub

Sub storage_DownloadCompleted (ServerPath As String, Success As Boolean)
    Log("Download completed.")
End Sub
The expected log messages would be:

Download started ...
Download completed.
Wait For is over. Continuing with next statement ...


Instead, I get:

Download started ...
Wait For is over. Continuing with next statement ...


... and Download completed never happens!

Now, if I comment out the Wait For statement, I get:

Download started ...
Download completed.


So it seems that the fact that I have a Wait For somehow disables the storage_DownloadCompleted event from firing. Makes no sense to me, and as I said, there's no such behavior in B4A with identical code. I can get around this by not using Wait For and putting code in storage_DownloadCompleted but that seems like a cowardly thing to do :rolleyes:.

Any possibility that Wait For in B4i somehow breaks the code in the iFirebaseStorage Library?
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
The expected log messages would be:

Download started ...
Download completed.
Wait For is over. Continuing with next statement ...
No, because you can't have two places where the event is triggered. Remove the routine (Sub storage_DownloadCompleted)
 
Upvote 0

Andris

Active Member
Licensed User
Longtime User
No, because you can't have two places where the event is triggered. Remove the routine (Sub storage_DownloadCompleted)
Interesting. Will try. So are you saying that if any code were included in (Sub storage_DownloadCompleted), I wouldn't be able to also use a Wait For with it?
 
Upvote 0

Andris

Active Member
Licensed User
Longtime User
No, because you can't have two places where the event is triggered. Remove the routine (Sub storage_DownloadCompleted)
I removed the routine (Sub storage_DownloadCompleted). Still the same behavior. Wait For doesn't wait and the download isn't available. In B4A, everything works fine with same code, even with the presence of (Sub storage_DownloadCompleted).
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Interesting. Will try. So are you saying that if any code were included in (Sub storage_DownloadCompleted), I wouldn't be able to also use a Wait For with it?
Yes. If you have both, Wait For and the sub, the sub will not be executed.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Yes. If you have both, Wait For and the sub, the sub will not be executed.
B4X:
Private Sub Button1_Click
    Dim HJob As HttpJob
    HJob.Initialize("Download", Me)
    HJob.Download("www.google.com")
    ' ***  Run with and without the next 3 lines  ***
    Wait For JobDone(j As HttpJob)
    Log("Success: " & j.Success)
    HJob.Release
End Sub

Private Sub JobDone(j As HttpJob)
    Log("JobDone sub")
End Sub
 
Upvote 0

Andris

Active Member
Licensed User
Longtime User
The fact that the Log after Wait For storage_DownloadCompleted is executed should mean that the download has in fact completed and the event raised to let the Wait For proceed. What is the value of the Success parameter? Put it in your Log statement.
Thanks Agraham, my lack of faith in my own stupidity has now been restored! Success was False, and ServerPath showed that I had a missing character in the file request. So of course it would come back False. Why I didn't examine these return values earlier is embarrassing. I'm sure it will now work just like B4A. Thanks again!!
 
Upvote 0
Solution

LucaMs

Expert
Licensed User
Longtime User
and ServerPath showed that I had a missing character in the file request. So of course it would come back False. Why I didn't examine these return values earlier is embarrassing. I'm sure it will now work just like B4A.
This is the problem: being sure the two versions were identical.

Thanks Agraham, my lack of faith in my own stupidity has now been restored!
Here no one is stupid (except me, maybe 😄) and no one is ever wrong (except Erel... maybe 😁)
 
Upvote 0
Top