Identify Browser, Engine, OS, CPU and Device Type/Model
Made with ♥ for Swift Server Side (Kitura, Vapor, Perfect...)
★★ Star our github repository to help us! ★★
UAParserSwift is a Swift-based library to parse User Agent string; it's a port of ua-parser-js by Faisal Salman created to be mainly used in Swift Server Side applications (Kitura, Vapor etc.). You can however use it on client side, all Apple's platforms are supported (iOS, macOS, tvOS and watchOS).
This library aims to identify detailed type of web browser, layout engine, operating system, cpu architecture, and device type/model, entirely from user-agent string with a relatively small footprint.
Other Libraries you may like
I'm also working on several other projects you may like. Take a look below:
| Library | Description | |-----------------|--------------------------------------------------| | SwiftDate | The best way to manage date/timezones in Swift | | Hydra | Write better async code: async/await & promises | | Flow | A new declarative approach to table managment. Forget datasource & delegates. | | SwiftRichString | Elegant & Painless NSAttributedString in Swift | | SwiftLocation | Efficient location manager | | SwiftMsgPack | Fast/efficient msgPack encoder/decoder |
How to use UAParserSwift
Usage of UAParserSwift is pretty simple; just allocate an
UAParser object along with the
User-Agent string you want to parse.
let parser = UAParser(agent: "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7") // Then call properties you want to read. // Parsed data are cached and evaluated lazily in order to // get the best performances. let identified_os = parser.os let identified_device = parser.device let identified_engine = parser.engine let identified_os = parser.os let identified_cpu = parser.cpu
Now you can call one of these properties to get parsed data (all properties are lazy created in order to keep parser lightweight):
.browser: return a
Browserobject with the browser's properties:
.device: return a
Deviceobject with device's informations:
.engine: return an
Engineobject with information about browser's engine:
.os: return an
OSobject with the information about host operation system:
.cpu: return a
CPUobject with the informations about host's device architecture:
Amaya, Android Browser, Arora, Avant, Baidu, Blazer, Bolt, Bowser, Camino, Chimera, Chrome [WebView], Chromium, Comodo Dragon, Conkeror, Dillo, Dolphin, Doris, Edge, Epiphany, Fennec, Firebird, Firefox, Flock, GoBrowser, iCab, ICE Browser, IceApe, IceCat, IceDragon, Iceweasel, IE[Mobile], Iron, Jasmine, K-Meleon, Konqueror, Kindle, Links, Lunascape, Lynx, Maemo, Maxthon, Midori, Minimo, MIUI Browser, [Mobile] Safari, Mosaic, Mozilla, Netfront, Netscape, NetSurf, Nokia, OmniWeb, Opera [Mini/Mobi/Tablet], PhantomJS, Phoenix, Polaris, QQBrowser, RockMelt, Silk, Skyfire, SeaMonkey, Sleipnir, SlimBrowser, Swiftfox, Tizen, UCBrowser, Vivaldi, w3m, WeChat, Yandex
Version: Determined dynamically
console, mobile, tablet, smarttv, wearable, embedded
Acer, Alcatel, Amazon, Apple, Archos, Asus, BenQ, BlackBerry, Dell, GeeksPhone, Google, HP, HTC, Huawei, Jolla, Lenovo, LG, Meizu, Microsoft, Motorola, Nexian, Nintendo, Nokia, Nvidia, OnePlus, Ouya, Palm, Panasonic, Pebble, Polytron, RIM, Samsung, Sharp, Siemens, Sony[Ericsson], Sprint, Xbox, Xiaomi, ZTE
Model: Determined dinamically
Amaya, EdgeHTML, Gecko, iCab, KHTML, Links, Lynx, NetFront, NetSurf, Presto, Tasman, Trident, w3m, WebKit
Engine Version: Determined dinamically
AIX, Amiga OS, Android, Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS, Contiki, Fedora, Firefox OS, FreeBSD, Debian, DragonFly, Gentoo, GNU, Haiku, Hurd, iOS, Joli, Linpus, Linux, Mac OS, Mageia, Mandriva, MeeGo, Minix, Mint, Morph OS, NetBSD, Nintendo, OpenBSD, OpenVMS, OS/2, Palm, PC-BSD, PCLinuxOS, Plan9, Playstation, QNX, RedHat, RIM Tablet OS, RISC OS, Sailfish, Series40, Slackware, Solaris, SUSE, Symbian, Tizen, Ubuntu, UNIX, VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk
Version: Determined dinamically
68k, amd64, arm, avr, ia[32/64], irix, mips, pa-risc, ppc, sparc
Unit Tests are available under the
Tests directory; actually they are the same tests available for ua-parser-js and all are passed successfully.
This library is written for Swift 4.x.
Swift Package Manager - Swift Server Side (Kitura,Vapor...)
Meow requires Swift 4.0 or greater to work. This is the official way to install packages for Swift Server Side. In your Package.swift, add the following to your dependencies array:
.package(url: "https://github.com/malcommac/UAParserSwift.git", from: "1.0.1")
To your target, add the "UAParserSwift" dependency.
.target(name: "Application", dependencies: ["UAParserSwift", ...])
Using CocoaPods - Client Side
- Add the pod
UAParserSwiftto your Podfile.
pod install from Terminal, then open your app's
.xcworkspace file to launch Xcode.
Using Carthage - Client Side
- Add the
malcommac/UAParserSwiftproject to your Cartfile.
Issues & Contributions
Please open an issue here on GitHub if you have a problem, suggestion, or other comment. Pull requests are welcome and encouraged.
Dual licensed under GPLv2 & MIT
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Help us keep the lights on
1.0.1 - Nov 5, 2017
Fixed an issue in /Sources folder structure which prevent SwiftPM to add library's dependency to the host project.
1.0.0 - Nov 5, 2017
This is the first stable version. It requires Swift 4.0 and while the main scope is to be used on Swift Server Side (Vapor, Kitura and others) it can also be used on client side: all Apple platforms are currently supported.