import IPAPI
IPAPI.Service.default.fetch {
if let result = try? $0.get() {
print("Geo IP result \(result).")
}
}
🔍 Lookup a domain
import IPAPI
Service.default.fetch(query: "apple.com") {
if let result = try? $0.get() {
print("Geo IP result \(result).")
}
}
✂️ Ask only for some specific fields
import IPAPI
Service.default.fetch(fields: [.ip, .latitude, .longitude, .organization]) {
if let result = try? $0.get() {
print("Geo IP result \(result).")
}
}
🇷🇴 Localization
import IPAPI
Service.default.fetch(language: "es") {
if let result = try? $0.get() {
print("Geo IP result \(result).")
}
}
import IPAPI
Service.default.batch([Service.Request(query: "208.80.152.201",
fields: [.countryName, .countryCode, .latitude, .longitude, .organization, .ip]),
Service.Request(query: "91.198.174.192", language: "es")]) {
if let result = try? $0.get() {
print("Geo IP result \(result).")
}
}
🔒 HTTPS requests
In order to use the API via HTTPS you must register for the “Pro” plan to get an API key. After you’ve done that you can set the API key like this and all your requests will use HTTPS.
import IPAPI
IPAPI.Service(pricingPlan: .pro(apiKey: "test-demo-pro")).fetch {
if let result = try? $0.get() {
print("Geo IP result \(result).")
}
}
IPAPI
http://ip-api.com Geolocation API client written in Swift.
Requirements
Installation
Carthage
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
To integrate IPAPI into your Xcode project using Carthage, specify it in your
Cartfile
:Run
carthage update
to build the framework and drag the builtIPAPI.framework
into your Xcode project.CocoaPods
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
To integrate IPAPI into your Xcode project using CocoaPods, specify it in your
Podfile
:Then, run the following command:
Swift Package Manager
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the
swift
compiler.Once you have your Swift package set up, adding IPAPI as a dependency is as easy as adding it to the
dependencies
value of yourPackage.swift
.Usage
🎯 Lookup the current IP address
🔍 Lookup a domain
✂️ Ask only for some specific fields
🇷🇴 Localization
*Checkout this page for the available languages.
📦 Batch request
🔒 HTTPS requests
In order to use the API via HTTPS you must register for the “Pro” plan to get an API key. After you’ve done that you can set the API key like this and all your requests will use HTTPS.
Contact
Let me know if you’re using or enjoying this product.