iOS Code Snippet Msgbox with timeout

Discussion in 'iOS Code Snippets' started by Erel, May 31, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed User

    A Msgbox that disappears automatically after the set timeout. The result is "Cancel".
    Code:
    Sub ShowMessageWithTimeout(text As String, timeout As Int) As ResumableSub
       
    Dim sf As Object = Msgbox2("Msg", text, "Title"Array ("Yes""No""Cancel"))
       
    Dim cancel(1As Boolean
       CheckForTimeout(sf, timeout, cancel)
       
    Wait For Msg_Click (ButtonText As String)
       cancel(
    0) = True
       
    Return ButtonText
    End Sub

    Private Sub CheckForTimeout (sf As NativeObject, delay As Int, cancel() As Boolean)
       
    Dim n As Long = DateTime.Now + delay
       
    Do While DateTime.Now < n
           
    If cancel(0) = True Then Return
           Sleep(
    100)
       
    Loop
       sf.RunMethod(
    "dismissWithClickedButtonIndex:animated:"Array(-1True))
       CallSubDelayed2(Me, 
    "Msg_Click""Cancel")
    End Sub
    Usage example:
    Code:
    Wait For (ShowMessageWithTimeout("testing???"4000)) Complete  (Result As String)
    Log(Result)
     
    Johan Hormaza, MarcoRome and JordiCP like this.
  2. JordiCP

    JordiCP Well-Known Member Licensed User

    Perfect! :)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice