iOS Question [Solved] dismiss msgBox programatically?

JordiCP

Expert
Licensed User
Longtime User
I'm showing a msgbox to notify a certain state to the user, and wait until the OK button is clicked.

When the home button is pressed app goes to background/inactive, and when it is called again, the msgBox is still there --> is it possible to dismiss it programatically somehow?

If it is not possible I'll use a panel instead, but perhaps there is a quick&simple workaround.
 

JordiCP

Expert
Licensed User
Longtime User
Thanks for the hint Marco ;)

I decided to test a bit more before taking this way, and at the end I arrived to a solution to solve this issue.

B4X:
Sub Process_Globals
   ...
   Dim myMsg as NativeObject
End Sub

' Here we show the message, as a part of our app
Sub showMessage
   myMsg = msgBox2(msg, "Dadada", "Dododo", Array("OK") )
    Wait For msg_Click (ButtonText As String)
    If ButtonText = "OK" Then
        ...
    End If
End Sub

' This is what we must call when we resume the app, in order to "kill" pending messageBoxes
Sub dismissMessageBoxIfAny
   If myMsg.isInitialized Then
        Dim nno As NativeObject = Me
        nno.RunMethod("dismiss:",Array(myMsg.getField("_alertController")))
     
      ' Not sure how to achieve the same directly. Tried this but crashed...
      ' myMsg.getField("_alertController").RunMethod("dismissViewControllerAnimated::",Array(True,Null))
   End if
End Sub

#If OBJC
- (void)dismiss: (UIAlertController*) mAlert {
[mAlert dismissViewControllerAnimated:YES completion:nil];
}
#end if

--- EDIT ---
It works, but.... the UI doesn't respond anymore, only to the next msgBox, so I must be missing something :mad:
 
Last edited:
Upvote 0
Top