iOS Question how to get WanIP using b4i

You will need to use an external service for this.
Such as this one: https://www.ipify.org/

Cross platform code: depends on iHttpUtils2 / OkHttpUtils2 and Json libraries
Code: Copy
'Returns an empty string if ip not available.
Private Sub FindExternalIp As ResumableSub
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download("https://api.ipify.org?format=json")
    Wait For (j) JobDone(j As HttpJob)
    Dim ip As String = ""
    If j.Success Then
        ip = j.GetString.As(JSON).ToMap.Get("ip")
    Else
        Log(LastException)
    End If
    j.Release
    Return ip
End Sub

Usage:
Code: Copy
Wait For (FindExternalIp) Complete (ip As String)
Log(ip)
 
Upvote 0
Back
Top