How to get the public IP address of the device

前端 未结 9 601
陌清茗
陌清茗 2020-12-29 10:32

I found this sample code to get all local IP addresses, but I don\'t find an easy solution to get the public IP.

A legacy class from Apple allowed to do that ... bu

9条回答
  •  抹茶落季
    2020-12-29 10:39

    In case you want to retrieve IP asynchronously, there is a way to do that using ipify.org and Alamofire in 1 line of code:

    Alamofire.request("https://api.ipify.org").responseString { (response) in
        print(response.result.value ?? "Unable to get IP")
    }
    

提交回复
热议问题