Retrieve your public IP address from ipify's API service.
import Ipify
Ipify.getPublicIPAddress { result in
switch result {
case .success(let ip):
print(ip) // "210.11.178.112"
case .failure(let error):
print(error.localizedDescription)
}
}
- Swift 4
- iOS 10+ / macOS 10.10+
Ipify is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Ipify"
github "vincent-peng/swift-ipify"
Vincent Peng, vincent@vincentpeng.me
Big thanks to Randall Degges for running and maintaining ipify!
Ipify is available under the MIT license. See the LICENSE file for more info.