Code Monkey home page Code Monkey logo

favicon's Introduction

FavIcon License Build Status Carthage compatible Swift 4.0 platforms

FavIcon is a tiny Swift library for downloading the favicon representing a website.

Wait, why is a library needed to do this? Surely it's just a simple HTTP GET of /favicon.ico, right? Right? Well. Go have a read of this StackOverflow post, and see how you feel afterwards.

Quick Start

CocoaPods

Note: CocoaPods (1.4.0 or later) is required.

Add it to your Podfile:

use_frameworks!
pod 'FavIcon', '~> 3.0.0'

Carthage

Add it to your Cartfile:

github "leonbreedt/FavIcon" ~> 3.0.0

Features

  • Detection of /favicon.ico if it exists
  • Parsing of the HTML at a URL, and scanning for appropriate <link> or <meta> tags that refer to icons using Apple, Google or Microsoft conventions.
  • Discovery of and parsing of Web Application manifest JSON files to obtain lists of icons.
  • Discovery of and parsing of Microsoft browser configuration XML files for obtaining lists of icons.

Yup. These are all potential ways of indicating that your website has an icon that can be used in user interfaces. Good work, fellow programmers. ๐Ÿ‘

Usage Example

Perhaps you have a location in your user interface where you want to put the icon of a website the user is currently visiting?

try FavIcon.downloadPreferred("https://apple.com") { result in
    if case let .success(image) = result {
      // On iOS, this is a UIImage, do something with it here.
      // This closure will be executed on the main queue, so it's safe to touch
      // the UI here.
    }
}

This will detect all of the available icons at the URL, and if it is able to determine their sizes, it will try to find the icon closest in size to your desired size, otherwise, it will prefer the largest icon. If it has no idea of the size of any of the icons, it will prefer the first one it found.

Of course, if this approach is too opaque for you, you can download them all using downloadAll(url:completion:).

Or perhaps youโ€™d like to take a stab at downloading them yourself at a later time, choosing which icon you prefer based on your own criteria, in which case scan(url:completion:) will give you information about the detected icons, which you can feed to download(url:completion:) for downloading at your convenience.

Example Project

See the iOS project in Example/ for a simple example of how to use the library.

License

Apache 2.0

favicon's People

Contributors

leonbreedt avatar tschmitz avatar

Watchers

 avatar

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.