OG is an OpenGraph parser in Swift.
You know the smart previews of websites that appear on Facebook or Twitter? OpenGraph is the spec's used to help make that happen.
Included is an Xcode Workspace containing an Xcodeproj for a dynamic library and an Xcode Playground to experiment with.
Requirements include iOS 8, Mac OS X 10.9, tvOS 9.0 or watchOS 2.0 and Swift 2.2 (included with Xcode 7.3.x).
To start using OG, you can add it to your project by:
github "zadr/OG" ~> 1.1.1
to your Cartfile
. pod 'OG', '~1.1.1
to your Podfile
. OG.xcodeproj
into your xcodeproj
, and adding OG.framework
as an embedded binary to the Target of your project. If you need any help, or find a bug, pleaseopen an issue! If you'd like to fix a bug or make any other contribution, feel free to open an issue,make a pull request, orupdate the wiki with anything that you found helpful.
There are two steps to take:
1.
Parse <meta>
tags out of html, keeping track of any relevant OpenGraph meta tags. To help with this, OG
provides a barebones parser:
let parser = Parser() let metaTagTracker = MetaTagTracker() parser.onFind = { (tag, values) in if !metaTagTracker.track(tag, values: values) { print("refusing to track non-meta tag /(tag) with values /(values)") } } let success = parser.parse(html)
2.
Turn a dictionary of attributes into an OpenGraph metadata object:
if success, let tag = Metadata.from(metaTagTracker.metadata) { print(tag) }
Probably, put a preview of the website on screen. To help with this, every OpenGraph Metadata
object has a title
, an imageUrl
, and a url
of what to open upon tap or click.