URLEmbeddedView automatically caches the object that is confirmed the Open Graph Protocol.

Overview

URLEmbeddedView

Platform Language Carthage compatible Version License

Features

  • Simple interface for fetching Open Graph Data
  • Be able to display Open Graph Data
  • Automatically caching Open Graph Data
  • Automatically caching Open Graph Image
  • Tap handleable
  • Clearable image cache
  • Clearable data cache
  • Support Swift3.2 (until 0.11.x)
  • Supprot Swift4.x (until 0.17.1)
  • Support Swift5 (since 0.18.0)
  • Support Carthage since 0.11.1
  • Support tvOS since 0.16.0
  • Custom implementation of OGData cache

Usage

To run the example project, clone the repo, and run carthage update from the Example directory first.

let embeddedView = URLEmbeddedView()
embeddedView.loadURL(urlString)

Layouts

  • Default

  • No Image

  • No response

Customization

embeddedView.textProvider[.Title].font = .boldSystemFontOfSize(18)
embeddedView.textProvider[.Title].fontColor = .lightGrayColor()
embeddedView.textProvider[.Title].numberOfLines = 2
//You can use ".Title", ".Description", ".Domain" and ".NoDataTitle"

Data and Image Cache

You can get Open Graph Data with OGDataProvider.

OGDataProvider.shared.fetchOGData(urlString: String, completion: ((OpenGraph.Data, Error?) -> Void)? = nil) -> String?
OGDataProvider.shared.deleteOGData(urlString: String, completion: ((Error?) -> Void)? = nil)
OGDataProvider.shared.deleteOGData(_ ogData: OpenGraph.Data, completion: ((Error?) -> Void)? = nil)

You can configure time interval for next updating of OGData. Default is 10 days.

OGDataProvider.shared.updateInterval = 10.days

You can get UIImage with OGImageProvider.

OGImageProvider.shared.loadImage(urlString: String, completion: ((UIImage?, Error?) -> Void)? = nil) -> NSURLSessionDataTask?
OGImageProvider.shared.clearMemoryCache()
OGImageProvider.shared.clearAllCache()

Custom Data Cache implementation

Default cache feature is using Core Data. If you want to use other cache features, please implement cache manager with OGDataCacheManagerProtocol. For example, URLEmbeddedView has OGDataNoCacheManager that feature is not using cache. If you want to use that feature, you can use like this.

OGDataProvider.shared.cacheManager = OGDataNoCacheManager()

You can implement custom cache feature and use it like this.

class MemoryCacheManager: OGDataCacheManagerProtocol {
    // implementation of required methods
}

OGDataProvider.shared.cacheManager = MemoryCacheManager()

OpenGraph.Data Properties

public let imageUrl: URL?
public let pageDescription: String?
public let pageTitle: String?
public let pageType: String?
public let siteName: String?
public let sourceUrl: URL?
public let url: URL?

OpenGraphDataDownloader

You can only use download feature of OGData with OpenGraphDataDownloader like this.

let urlString = ...
OpenGraphDataDownloader.shared.fetchOGData(urlString: urlString) { result in
    switch result {
    case let .success(data, isExpired):
        // do something
    case let .failure(error, isExpired):
        // do something
    }
}

If you use OGDataProvider with OGDataNoCacheManager, it is almost same process.

OGDataProvider.shared.cacheManager = OGDataNoCacheManager()
let urlString = ...
OGDataProvider.shared.fetchOGData(urlString: urlString) { ogData, error in
    // do something
}

Installation

CocoaPods

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

# Uncomment the next line to define a global platform for your project
# platform :ios, '8.0'

target 'Your Project Name' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for URLEmbeddedViewSample
  pod "URLEmbeddedView"
end

Carthage

If you’re using Carthage, simply add NoticeObserveKit to your Cartfile:

github "marty-suzuki/URLEmbeddedView"

Use in Objective-C

#import <URLEmbeddedView/URLEmbeddedView-Swift.h>

- (void)viewDidLoad {
    [super viewDidLoad];
    URLEmbeddedView *embeddedView = [[URLEmbeddedView alloc] init];
    [self.view addSubView:embeddedView];
    [embeddedView loadURL:@"https://github.com/" completion:nil];
}

- (void)setUpdateInterval {
  [OGDataProvider sharedInstance].updateInterval = [NSNumber days:10];
}

- (void)fetchOpenGraphData {
  [[OGDataProvider sharedInstance] fetchOGDataWithUrlString:self.textView.text
                                            completion:^(OpenGraphData *data, NSError *error) {
      NSLog(@"OpenGraphData = %@", data);
  }];
}

Here is Objective-C sample.

Special Thanks

Requirements

  • Xcode 10.2 or greater
  • iOS 8.0 or greater
  • tvOS 10.0 or greater
  • UIKit
  • CoreData
  • CoreGraphics

Other

Author

Taiki Suzuki, [email protected]

License

URLEmbeddedView is available under the MIT license. See the LICENSE file for more info.

Comments
  • Crash using Carthage install in Objective-C Project

    Crash using Carthage install in Objective-C Project

    When installed with Carthage in an Objective-C project, this crashes when the list cells are shown:

    let fetchedList = (try? managedObjectContext.fetch(fetchRequest))

    in the

    fetchOGData

    method.

    opened by inPhilly 46
  • Related to issue number #39

    Related to issue number #39

    Hi, Suzuki Sorry to bother you again, How can I update to the specific version of the pod you specified in that bug number #39. I tried updating to the latest version (0.12.0). But it won't help for me because I'm using 8.3.3 and the pod is upgraded for Swift 4

    opened by sarathdev 14
  • OpenGraphData fields are not visible in ObjC

    OpenGraphData fields are not visible in ObjC

    https://github.com/marty-suzuki/URLEmbeddedView/blob/9750da46e0d1eeae55cf7fcbb618ed0bbc8e488b/Example/URLEmbeddedViewSample/OGObjcSampleViewController.m#L54

    This example doesn't compile with error: Property 'siteName' not found on object of type 'OpenGraphData *'

    Looks like this will fix the issue: https://stackoverflow.com/a/45656756/1321401

    opened by Luten 12
  • unable to use it in Objective C project

    unable to use it in Objective C project

    Tried using it in objective C, even after adding use_frameworks! in podfile, It seems use_frameworks! doesn't work and also tried to add it manually in share extension of my app, but files in URLEmbeddedView source like OGDataProvider unable to access Kanna and Misterfusion files embedded in this pod source, even after adding Kanna and Misterfusion seperately using git clone.

    opened by github-prathma 12
  • File not found for obj-c

    File not found for obj-c

    Hi, As mentioned in the obj-c example, there is no file URLEmbeddedView/URLEmbeddedView-Swift.h. Please have a look in to it. I am trying to port that to C#.

    opened by guntidheerajkumar 12
  • OG data is not fully parsed

    OG data is not fully parsed

    Tried with version 0.15.3 (we need ios8) Here are the results of library for url https://www.imdb.com/title/tt5095030/:

    createdAt = Wed Jul 18 13:25:53 2018
    imageUrl = (null)
    pageDescription = Directed by Peyton Reed.  With Paul Rudd, Evangeline Lilly, Michael Peña, Walton Goggins. As Scott Lang balances being both a Super Hero and a father, Hope van Dyne and Dr. Hank Pym present an urgent new mission that finds the Ant-Man fighting alongside The Wasp to uncover secrets from their past.
    pageTitle = (null)
    pageType = (null)
    siteName = (null)
    sourceUrl = https://www.imdb.com/title/tt5095030/
    updatedAt = Wed Jul 18 13:25:57 2018
    url = http://www.imdb.com/title/tt5095030/
    

    While there are not null tags (can be seen in source html, or by tools like https://opengraphcheck.com/result.php?url=https%3A%2F%2Fwww.imdb.com%2Ftitle%2Ftt5095030%2F#.W07dRdgzZTY)

    og:url | http://www.imdb.com/title/tt5095030/
    og:image | https://m.media-amazon.com/images/M/MV5BYjcyYTk0N2YtMzc4ZC00Y2E0LWFkNDgtNjE1MzZmMGE1YjY1XkEyXkFqcGdeQXVyMTMxODk2OTU@._V1_UY1200_CR90,0,630,1200_AL_.jpg
    og:type | video.movie
    og:title | Ant-Man and the Wasp (2018)
    og:site_name | IMDb
    og:description | Directed by Peyton Reed. With Paul Rudd, Evangeline Lilly, Michael Peña, Walton Goggins. As Scott Lang balances being both a Super Hero and a father, Hope van Dyne and Dr. Hank Pym present an urgent new mission that finds the Ant-Man fighting alongside The Wasp to uncover secrets from their past.
    
    opened by Luten 6
  • How can I get image URL from OpenGraphData?

    How can I get image URL from OpenGraphData?

    Hi,

    I am using URLEmbeddedView to get meta data. I am not getting image URL since library has been updated. I am using below code to get meta data.

    [[OGDataProvider sharedInstance] fetchOGDataWithUrlString:@"www.testurl.com" completion:^(OpenGraphData * obj_data, NSError * error) {
    
        NSLog(@"data object = %@",obj_data);
    }];
    

    So how can I get imageURL, pageTitle, createdAt, pageType, siteName, sourceUrl, url using OpenGraphData object?

    opened by parthpatel1105 6
  • Cannot fetch image

    Cannot fetch image

    Load Url return can not fetch image with

    url : https://www.youtube.com/watch?v=IGyvbGHxUdg

    but when i check in this website. There is og:image tag. Please help me. thanks you.

    screen shot 2017-09-28 at 3 03 32 pm
    opened by AyeChanPyaeSone 6
  • Not getting imageUrl in some cases

    Not getting imageUrl in some cases

    Thanks for this great library. I am facing a problem in getting "imageUrl" for some case.

    http://www.runnersworld.com/race-training/how-to-taper-for-your-first-half-marathon?utm_source=facebook.com&utm_medium=Social&utm_term=580876710&utm_campaign=Runner%E2%80%99s%20World

    I am using OGDataProvider to extract the data. [[OGDataProvider sharedInstance] fetchOGDataWithUrlString:url completion:^(OGData data, NSError error)

    Any help is much appreciated.

    opened by RakeshImpinge 6
  • Value of type '[(_, CGFloat?)]' has no member 'compactMap'

    Value of type '[(_, CGFloat?)]' has no member 'compactMap'

    func addConstraints(with view: UIView, size: Size, relatedBy relation: NSLayoutRelation = .equal, multiplier: CGFloat = 1) { view.translatesAutoresizingMaskIntoConstraints = false addConstraints([ (.width, size.width), (.height, size.height) ] .compactMap { (value: (NSLayoutAttribute, CGFloat?)) in value.1.map { .init(item: view, attribute: value.0, relatedBy: relation, toItem: nil, attribute: .notAnAttribute, multiplier: multiplier, constant: $0) } } ) }

    opened by Ilesh 3
  • Not getting website image for specific URL

    Not getting website image for specific URL

    I am using this framework for objective C and it's working fine here. But sometimes I am not getting image of particular website and not getting website title properly. Here I am providing you one website URL as sample in which I am facing both issue for image and title.

    https://www.cnbc.com/2018/05/02/effectiveness-of-tesla-autopilot-was-not-assessed-nhtsa.html

    In above URL I am not getting image and title with uneven characters like &#039;

    https://feedproxy.google.com/~r/entrepreneur/latest/~3/EQ33cmQbh3Q/312846

    For this URL I am getting null website title. I am using latest code for URLEmbeddedView.

    @marty-suzuki Please do needful help for this issue.

    Thank you.

    opened by parthpatel1105 3
  • Does not load imageURL or title for basic websites

    Does not load imageURL or title for basic websites

    I am trying to fetch data from sites such as https://www.facebook.com, or https://www.youtube.com. Nothing shows up in the data. I remember this used to work a few weeks ago.

    However, when I try to fetch specific youtube videos, everything appears (images, and so on).

    Why does this happen?

    I have the newest pod installed in my project (Objective-C). I had installed it through CocoaPods.

    Thanks for any help!

    opened by 7er0 2
  • Crashes on load frequently

    Crashes on load frequently

    Thank you for the awesome pod!

    Unfortunatley, I am unable to use it because it frequently crashes here:

    #8 0x00000001063bbaa0 in closure #1 in OGDataProvider.fetchOGData(urlString:completion:) at .../Pods/URLEmbeddedView/URLEmbeddedView/Core/Cache/Data/OGDataProvider.swift:58

    The main error I get is "Thread 1: EXC_BAD_ACCESS (code=1, address=0x8)" but XCode does not point to a particular line of code. This did not happen before using the pod, but it does now, and it always occurs during the same closure above.

    I am loading one URLEmbeddedView per cell in a tableview with several cells, and usually a different link for each view. I am loading the View in cellForRowAt

    The only code I am using is:

    cell.embeddedLinkView.load(urlString: post._pub._link) cell.embeddedLinkView.didTapHandler = { [weak self] _, url in guard let self = self else { return } .... }

    in the cell:

    let embeddedLinkView = URLEmbeddedView() ....

    self.embeddedLinkView.translatesAutoresizingMaskIntoConstraints = false self.embeddedLinkView.height(constant: 100) self.embeddedLinkView.width(constant: self.frame.width) myStack.addArrangedSubview(self.embeddedLinkView) ....

    self.embeddedLinkView.isHidden = !self.data._pub.linkExists() self.embeddedLinkView.textProvider[.title].fontColor = UIColor.lightGray self.embeddedLinkView.textProvider[.description].fontColor = UIColor.lightGray self.embeddedLinkView.textProvider[.domain].fontColor = UIColor.lightGray.withAlphaComponent(0.7) self.embeddedLinkView.textProvider[.noDataTitle].fontColor = UIColor.lightGray.withAlphaComponent(0.6)

    opened by joshwolff1 0
  • Crash on fetch

    Crash on fetch

    This is crash from our client, we don't know yet any reproduction steps. But maybe the crashlog would be enough for you to catch a problem

    Crash log:

    #14. Crashed: com.OGDataProvider.URLEmbeddedView
    0  libsystem_kernel.dylib         0x1840e92ec __pthread_kill + 8
    1  libsystem_pthread.dylib        0x18428a288 pthread_kill$VARIANT$mp + 376
    2  libsystem_c.dylib              0x184057d0c abort + 140
    3  URLEmbeddedView                0x1023bf3c8 $S15URLEmbeddedView18OGDataCacheManagerC26persistentStoreCoordinatorSo012NSPersistentgH0CvgAFyXEfU_ + 1678
    4  URLEmbeddedView                0x1023becbc $S15URLEmbeddedView18OGDataCacheManagerC26writerManagedObjectContextSo09NSManagedhI0CvgAFyXEfU_ + 56
    5  URLEmbeddedView                0x1023bec24 $S15URLEmbeddedView18OGDataCacheManagerC26updateManagedObjectContextSo09NSManagedhI0CvgAFyXEfU_Tm + 112
    6  URLEmbeddedView                0x1023bec24 $S15URLEmbeddedView18OGDataCacheManagerC26updateManagedObjectContextSo09NSManagedhI0CvgAFyXEfU_Tm + 112
    7  URLEmbeddedView                0x1023be010 $S15URLEmbeddedView18OGDataCacheManagerC24fetchOrInsertOGCacheData3url10completionySS_yAA0iJ0CctF + 96
    8  URLEmbeddedView                0x1023be3a0 $S15URLEmbeddedView18OGDataCacheManagerC24fetchOrInsertOGCacheData3url10completionySS_yAA0iJ0CctFTo + 128
    9  URLEmbeddedView                0x1023c67e4 $S15URLEmbeddedView14OGDataProviderC05fetchC09urlString10completionAA4TaskCSS_yAA9OpenGraphO4DataV_s5Error_pSgtcSgtFyycfU_ + 352
    10 URLEmbeddedView                0x1023c5a68 $SIeg_IeyB_TR + 36
    11 libdispatch.dylib              0x183f54b24 _dispatch_call_block_and_release + 24
    12 libdispatch.dylib              0x183f54ae4 _dispatch_client_callout + 16
    13 libdispatch.dylib              0x183f5cf18 _dispatch_continuation_pop$VARIANT$mp + 424
    14 libdispatch.dylib              0x183f5b850 _dispatch_async_redirect_invoke$VARIANT$mp + 604
    15 libdispatch.dylib              0x183f61d30 _dispatch_root_queue_drain + 588
    16 libdispatch.dylib              0x183f61a80 _dispatch_worker_thread3 + 120
    17 libsystem_pthread.dylib        0x184287fac _pthread_wqthread + 1176
    18 libsystem_pthread.dylib        0x184287b08 start_wqthread + 4
    
    opened by Luten 7
  • OG data not read properly on certain sites

    OG data not read properly on certain sites

    https://theyeshiva.net returns bad data but works fine on ios iMessage app

    image

    also no image on https://washingtonpost.com but is ok on iMessage

    here is the iMessage successful loads image

    opened by felixdkatt 6
Releases(0.18.0)
Owner
Taiki Suzuki
AbemaTV / University of Aizu 18th
Taiki Suzuki
Protocol oriented, type safe, scalable design system foundation swift framework for iOS.

Doric: Design System Foundation Design System foundation written in Swift. Protocol oriented, type safe, scalable framework for iOS. Features Requirem

Jay 93 Dec 6, 2022
Protocol to handle initial Loadings, Empty Views and Error Handling in a ViewController & views

StatusProvider Protocol to handle initial Loadings, Empty Views and Error Handling in a ViewController & views CocoaPods Podfile pod 'StatusProvider'

Mario Hahn 887 Dec 22, 2022
React.js like Mixin. More powerful Protocol-Oriented Programming.

Mixin ?? Why? Swift is Protocol-Oriented Programming, and it's more powerful by default implementations of extensions of protocols. You can mixin meth

Wan-Huang Yang 45 Dec 28, 2021
💻This is an open source project of the Windows 11 desktop client implemented using SwiftUI.

?? ??This is an open source project of the Windows 11 desktop client implemented using SwiftUI.

晋先森 173 Jan 2, 2023
DivKit is an open source Server-Driven UI (SDUI) framework.

DivKit ?? is an open source Server-Driven UI (SDUI) framework. It allows you to roll out server-sourced updates to different app versions. Also, it can be used for fast UI prototyping, allowing you to write a layout once and then ship it to iOS, Android, and Web platforms.

DivKit 1.6k Jan 9, 2023
URLEmbeddedView automatically caches the object that is confirmed the Open Graph Protocol.

URLEmbeddedView Features Simple interface for fetching Open Graph Data Be able to display Open Graph Data Automatically caching Open Graph Data Automa

Taiki Suzuki 643 Dec 20, 2022
A library and tool for interacting with both the local and remote asset caches.

Asset Cache Tool A library and tool for interacting with both the local and remote asset caches. This is based on research I did a few years ago on th

Kenneth Endfinger 20 Dec 23, 2022
A protocol that allows any class to be printed as if it were a struct or a JSON object.

ReflectedStringConvertible A protocol that extends CustomStringConvertible and uses reflection to add a detailed textual representation to any class.

Matt Comi 65 Dec 24, 2022
🎧 Protocol driven object observation

Listenable Swift object that provides an observable platform for multiple listeners. Requirements iOS 9.0+ Xcode 9.x+ Swift 4 Installation Listenable

Merrick Sapsford 9 Nov 30, 2022
A type-safe, protocol-based, pure Swift database offering effortless persistence of any object

There are many libraries out there that aims to help developers easily create and use SQLite databases. Unfortunately developers still have to get bogged down in simple tasks such as writing table definitions and SQL queries. SwiftyDB automatically handles everything you don't want to spend your time doing.

Øyvind Grimnes 489 Sep 9, 2022
SwiftyOpenGraph - A swift library that retrieves structured open graph data from webpages.

SwiftyOpenGraph Usage Initialization Base Properties Types Installation License Usage Initialization You use SwiftyOpenGraph by initializing OpenGraph

Quintschaf 1 Jan 6, 2022
Infowind - An Open Graph Metadata extension for iOS, iPadOS & MacOS

Infowind ?? InfoWind is an Open Graph Protocol based Safari extension for iOS, i

Gokul Nair 0 Jun 22, 2022
Solana + RxSolana This is a open source library on pure swift for Solana protocol

The objective is to create a cross platform, fully functional, highly tested and less depencies as posible. The project is still at initial stage. Lots of changes chan happen to the exposed api.

Arturo Jamaica 138 Dec 15, 2022
An adaptive scrollable graph view for iOS to visualise simple discrete datasets. Written in Swift.

ScrollableGraphView Announcements 9-7-2017 - Version 4: Version 4 was released which adds multiple plots, dynamic reloading of values, more reference

Phillip 5.3k Jan 5, 2023
Graph is a semantic database that is used to create data-driven applications.

Welcome to Graph Graph is a semantic database that is used to create data-driven applications. Download the latest sample. Features iCloud Support Mul

Cosmicmind 875 Oct 5, 2022
Framework-level dependency graph generator for Xcode projects - with support for custom graphing

XCGrapher xcgrapher is, by default, a framework-level dependency graph generator for Xcode projects. It works by reading local clones of the source, s

Max Chuquimia 74 Dec 14, 2022
A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.

⚡ A powerful & easy to use chart library for Android ⚡ Charts is the iOS version of this library Table of Contents Quick Start Gradle Maven Documentat

Philipp Jahoda 36k Jan 5, 2023
Simple and intuitive iOS chart library. Contribution graph, clock chart, and bar chart.

TEAChart Simple and intuitive iOS chart library, for Pomotodo app. Contribution graph, clock chart, and bar chart. Supports Storyboard and is fully ac

柳东原 · Dongyuan Liu 1.2k Nov 29, 2022
iOS/iPhone/iPad Chart, Graph. Event handling and animation supported.

#EChart A highly extendable, easy to use chart with event handling, animation supported. ##Test How To Use Download and run the EChartDemo project is

Scott Zhu 646 Dec 27, 2022
A Graph Data Structure in Pure Swift

SwiftGraph SwiftGraph is a pure Swift (no Cocoa) implementation of a graph data structure, appropriate for use on all platforms Swift supports (iOS, m

David Kopec 700 Dec 16, 2022