Code Monkey home page Code Monkey logo

mmdb-swift's Introduction

MMDB-Swift

Language Version Carthage Compatible SPM Compatible Platform

A tiny wrapper for libmaxminddb which allows you to lookup Geo data by IP address.


NOTE From v0.5.0, MMDB-Swift no longer bundles GeoLite2 database due to the license change. Developers should download the binary version from the Maxmind website.

CocoaPods

MMDB-Swift is available through CocoaPods. To install it, simply add the following line to your Podfile:

platform :ios, '8.0'
use_frameworks!
pod "MMDB-Swift"

Then, run the following command:

pod install

Carthage

To integrate MMDB-Swift into your Xcode project using Carthage, add the following line to your Cartfile:

github "lexrus/MMDB-Swift"

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

Swift Package Manager

Package.swift

import PackageDescription

let package = Package(
          name: "YOUR_AWESOME_PROJECT",
       targets: [],
  dependencies: [
                  .Package(
                    url: "https://github.com/lexrus/MMDB-Swift",
               versions: "0.0.1" ..< Version.max
                  )
                ]
)

Usage

guard let db = MMDB("PATH_TO_THE_DATABASE") else {
  print("Failed to open DB.")
  return
}
if let country = db.lookup("8.8.4.4") {
  print(country)
}

This outputs:

{
  "continent": {
    "code": "NA",
    "names": {
      "ja": "北アメリカ",
      "en": "North America",
      "ru": "Северная Америка",
      "es": "Norteamérica",
      "de": "Nordamerika",
      "zh-CN": "北美洲",
      "fr": "Amérique du Nord",
      "pt-BR": "América do Norte"
    }
  },
  "isoCode": "US",
  "names": {
    "ja": "アメリカ合衆国",
    "en": "United States",
    "ru": "США",
    "es": "Estados Unidos",
    "de": "USA",
    "zh-CN": "美国",
    "fr": "États-Unis",
    "pt-BR": "Estados Unidos"
  }
}

Notice that country is a struct defined as:

public struct MMDBContinent {
  var code: String?
  var names: [String: String]?
}

public struct MMDBCountry: CustomStringConvertible {
  var continent = MMDBContinent()
  var isoCode = ""
  var names = [String: String]()
  ...
}

Author

Lex Tang (Twitter: @lexrus)

License

MMDB-Swift is available under the Apache License Version 2.0. See the LICENSE file for more info.

The GeoLite2 databases are distributed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.

mmdb-swift's People

Contributors

jeffma avatar lexrus avatar simpzan avatar zhuhaow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mmdb-swift's Issues

carthage update --no-use-binaries --platform ios error

*** Building scheme "MMDB-iOS" in MMDB.xcodeproj
Build Failed
Task failed with exit code 65:
/usr/bin/xcrun xcodebuild -project /Volumes/Data/local_data/git.pushyou.net/pushme/ladder-ios/Carthage/Checkouts/MMDB-Swift/MMDB.xcodeproj -scheme MMDB-iOS -configuration Release -derivedDataPath /Users/jacksonpan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.4.1_9F2000/MMDB-Swift/0.2.8 -sdk iphoneos ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES archive -archivePath /var/folders/2p/z58pwll102710mwdb_2yc3jh0000gn/T/MMDB-Swift SKIP_INSTALL=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=NO CLANG_ENABLE_CODE_COVERAGE=NO STRIP_INSTALLED_PRODUCT=NO (launched in /Volumes/Data/local_data/git.pushyou.net/pushme/ladder-ios/Carthage/Checkouts/MMDB-Swift)

This usually indicates that project itself failed to compile. Please check the xcodebuild log for more details: /var/folders/2p/z58pwll102710mwdb_2yc3jh0000gn/T/carthage-xcodebuild.z9Ocns.log

carthage-xcodebuild.z9Ocns.log

Swift Package manager error

Showing All Messages
Source files for target MMDB should be located under 'Sources/MMDB', or a custom sources path can be set with the 'path' property in Package.swift

memory leaking

let status = MMDB_get_entry_data_list(&entry, &list)
if status != MMDB_SUCCESS {
return nil
}
you should free memory when status is success:

    defer {
        MMDB_free_entry_data_list(list)
    } 

Add package on Linux

Hi,
I have a problem during adding MMDB-Swift to linux(Ubuntu 16.04) swift(3.0.2) project:
Package.swift:
import PackageDescription

let package = Package(
    name: "Antiparsing_v3",
    targets: [],
    dependencies: [
        .Package(url: "https://github.com/lexrus/MMDB-Swift.git", versions: Version(0,0,1)..<Version(0,2,0)),
    ]
)

When I try to build project, I get error:
$ swift build
warning: refname '0.0.2' is ambiguous.
warning: refname '0.0.2' is ambiguous.
HEAD is now at 7d14b1d Clean up.
Resolved version: 0.0.2
error: The package at `.../Packages/MMDB-Swift.git' has no Package.swift for the specific version: 0.0.2

swift4?

汤哥,用swift4 ,编译这个的时候总是提示没有选中Bitcode,但是我编译的时候明明正常选择了(”Build Settings”->”Enable Bitcode”),指定的的地方配置了 -fembed-bitcode ,其他动态库都能正常打包成功。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.