Swiftpack.co - Package - arturgrigor/IPAPI

Carthage compatible Build Status CocoaPods Compatible Platform Twitter

IPAPI

http://ip-api.com Geolocation API client written in Swift.

Requirements

  • iOS 8.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 8.0+
  • Swift 4+

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:

$ brew update
$ brew install carthage

To integrate IPAPI into your Xcode project using Carthage, specify it in your Cartfile:

github "arturgrigor/IPAPI" ~> 1.2

Run carthage update to build the framework and drag the built IPAPI.framework into your Xcode project.

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 1.1.0+ is required.

To integrate IPAPI into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'IPAPI', '~> 1.2'
end

Then, run the following command:

$ pod install

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but IPAPI does support its use on supported platforms.

Once you have your Swift package set up, adding IPAPI as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .Package(url: "https://github.com/arturgrigor/IPAPI.git", majorVersion: 1)
]

Usage

🎯 Lookup the current IP address

import IPAPI

IPAPI.Service.default.fetch { result, error in
            if let result = result {
                print("Geo IP result \(result).")
            }
        }

🔍 Lookup a domain

import IPAPI

Service.default.fetch(query: "apple.com") { result, error in
            if let result = result {
                print("Geo IP result \(result).")
            }
        }

✂️ Ask only for some specific fields

import IPAPI

Service.default.fetch(fields: [.ip, .latitude, .longitude, .organization]) { result, error in
            if let result = result {
                print("Geo IP result \(result).")
            }
        }

🇷🇴 Localization

import IPAPI

Service.default.fetch(language: "es") { result, error in
            if let result = result {
                print("Geo IP result \(result).")
            }
        }

*Checkout this page for the available languages.

📦 Batch request

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")]) { result, error in
            if let result = result {
                print("Geo IP result \(result).")
            }
        }

Contact

Let me know if you're using or enjoying this product.

Github

link
Stars: 5
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

1.2.0 - Oct 27, 2017

Updated

  • The project to work with Xcode 9 on Swift 4.0.