Swiftpack.co -  leonbreedt/FavIcon as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
leonbreedt/FavIcon
Swift library to detect icons supported by a website.
.package(url: "https://github.com/leonbreedt/FavIcon.git", from: "3.1.0")

FavIcon License Build Status Carthage compatible Swift 5.0 platforms

Not actively maintained

I am no longer able to spend as much time working on this library.

You may want to consider an using an alternative, such as FavIconFinder, which is pure Swift and is more actively maintained.

What is this?

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

Swift Package Manager

Add it to your Package.swift as a dependency:

// swift-tools-version:5.0
import PackageDescription

let package = Package(
    ...
    dependencies: [
        .package(url: "https://github.com/leonbreedt/FavIcon.git", from: "3.1.0"),
    ],
)

CocoaPods

Note: CocoaPods (1.4.0 or later) is required.

Add it to your Podfile:

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

Carthage

Add it to your Cartfile:

github "leonbreedt/FavIcon" ~> 3.1.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

GitHub

link
Stars: 121
Last commit: 4 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

3.1.0: Support Swift 5, use Apple bundled libxml2 🎉
1 year ago

[FEATURES]

  • Switch to Swift 5.0.
  • Use libxml2 that Apple bundles with the latest SDKs. This is a big enough ease of use change that I'm happy to require people build using Xcode 11.4, as it means no more weird module errors or libxml2 link failures.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API