转载

[iOS] SwiftLinkPreview:根据 URL 提取网页摘要预览库

Swift Link Preview

It makes a preview from an url, grabbing all the information such as title, relevant texts and images.

UTF-8 Extended UTF-8
[iOS] SwiftLinkPreview:根据 URL 提取网页摘要预览库 [iOS] SwiftLinkPreview:根据 URL 提取网页摘要预览库
Gallery Video Websites
[iOS] SwiftLinkPreview:根据 URL 提取网页摘要预览库 [iOS] SwiftLinkPreview:根据 URL 提取网页摘要预览库
Images
[iOS] SwiftLinkPreview:根据 URL 提取网页摘要预览库

FLOW

[iOS] SwiftLinkPreview:根据 URL 提取网页摘要预览库

Requirements and Details

  • iOS 8.0+
  • Xcode 7.3 or above
  • Built with Swift 2.2

Installation

CocoaPods

source 'https://github.com/CocoaPods/Specs.git'     platform :ios, '8.0'      target 'Your Project Name' do         use_frameworks!         // ...         pod 'SwiftLinkPreview', '~> 0.0.3'         // ...     end

Carthage

// ...     github "LeonardoCardoso/SwiftLinkPreview" ~> 0.0.3     // ...

Manually

Although it's not recommended, you just need to drop SwiftLinkPreview folder into Xcode project (make sure to enable "Copy items if needed" and "Create groups").

Usage

Instatiating

import SwiftLinkPreview  // ...  let slp = SwiftLinkPreview()

Requesting preview

slp.preview(     "Text containing url",     onSuccess: { result in          print("/(result)")      },     onError: { error in          print("/(error)")      } )

resultis a dictionary [String: AnyObject] like:

[    "url": "original URL",                               // NSURL    "finalUrl": "final ~unshortened~ URL.",              // NSURL    "canonicalUrl": "canonical URL",                     // NSURL    "title": "title",                                    // String    "description": "page description or relevant text",  // String    "images": ["array of URLs of the images"],           // String array    "image": "main image"                                // String ]

Cancelling a request

slp.cancel()

Important

You need to set Allow Arbitrary Loads to YES on your project's Info.plist file.

[iOS] SwiftLinkPreview:根据 URL 提取网页摘要预览库

TIPS

Not all websites will have their info brought, you can treat the info that your implementation gets as you like. But here are two tips about posting a preview:

  • If some info is missing, you can offer the user to enter it. Take for example the description.
  • If more than one image is fetched, you can offer the user the feature of picking one image.

Information and Contact

Developed by@LeonardoCardoso.

For more information, please visit http://ios.leocardz.com/swift-link-preview/ .

Contact me either by Twitter @leocardz or emailing me to contact@leocardz.com .

Related Projects

  • Link Preview (PHP + Angular + Bootstrap)
  • Android Link Preview

License

The MIT License (MIT)  Copyright (c) 2016 Leonardo Cardoso  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.  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
原文  https://github.com/LeonardoCardoso/SwiftLinkPreview
正文到此结束
Loading...