Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

marty-suzuki/URLEmbeddedView

Repository files navigation

PlatformLanguageCarthage compatibleVersionLicense

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 runcarthage update from the Example directory first.

letembeddedView=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 withOGDataProvider.

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 withOGImageProvider.

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 withOGDataCacheManagerProtocol.For example, URLEmbeddedView hasOGDataNoCacheManager 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.

classMemoryCacheManager:OGDataCacheManagerProtocol{    // implementation of required methods}OGDataProvider.shared.cacheManager=MemoryCacheManager()

OpenGraph.Data Properties

publicletimageUrl:URL?publicletpageDescription:String?publicletpageTitle:String?publicletpageType:String?publicletsiteName:String?publicletsourceUrl:URL?publicleturl:URL?

OpenGraphDataDownloader

You can only use download feature of OGData withOpenGraphDataDownloader like this.

leturlString=...OpenGraphDataDownloader.shared.fetchOGData(urlString: urlString){ resultinswitch result{caselet.success(data, isExpired):        // do something    caselet.failure(error, isExpired):        // do something}}

If you useOGDataProvider withOGDataNoCacheManager, it is almost same process.

OGDataProvider.shared.cacheManager=OGDataNoCacheManager()leturlString=...OGDataProvider.shared.fetchOGData(urlString: urlString){ ogData, errorin    // do something}

Installation

CocoaPods

URLEmbeddedView is available throughCocoaPods. To installit, 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 frameworksuse_frameworks!# Pods for URLEmbeddedViewSamplepod"URLEmbeddedView"end

Carthage

If you’re usingCarthage, simply addNoticeObserveKit to yourCartfile:

github"marty-suzuki/URLEmbeddedView"

Use in Objective-C

#import<URLEmbeddedView/URLEmbeddedView-Swift.h>- (void)viewDidLoad {    [superviewDidLoad];    URLEmbeddedView *embeddedView = [[URLEmbeddedViewalloc]init];    [self.viewaddSubView:embeddedView];    [embeddedViewloadURL:@"https://github.com/"completion:nil];}- (void)setUpdateInterval {  [OGDataProvidersharedInstance].updateInterval = [NSNumberdays:10];}- (void)fetchOpenGraphData {  [[OGDataProvidersharedInstance]fetchOGDataWithUrlString:self.textView.textcompletion:^(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,s1180183@gmail.com

License

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp