Link Previewer for iOS, macOS, watchOS and tvOS
It makes a preview from an URL, grabbing all the information such as title, relevant texts and images.
Visual Examples
UTF-8 | Extended UTF-8 | Gallery |
---|---|---|
![]() |
![]() |
![]() |
Video Websites | Images | |
![]() |
![]() |
Requirements and Details
- iOS 8.0+ / macOS 10.11+ / tvOS 9.0+ / watchOS 2.0+
- Xcode 8.0+
- Built with Swift 3
Installation
CocoaPods
To use SwiftLinkPreview as a pod package just add the following in your Podfile file.
Carthage
To use SwiftLinkPreview as a Carthage module package just add the following in your Cartfile file.
Swift Package Manager
To use SwiftLinkPreview as a Swift Package Manager package just add the following in your Package.swift file.
Manually
You just need to drop all contents in Sources
folder, but .plist files, into Xcode project (make sure to enable "Copy items if needed" and "Create groups").
Usage
Instatiating
Requesting preview
result is a struct Response
:
Cancelling a request
Enabling and accessing cache
SLP has a built-in memory cache, so create your object as the following:
To get the cached response:
If you want to create your own cache, just implement this protocol and use it on the object initializer.
FLOW
Important
You need to set Allow Arbitrary Loads
to YES
on your project's Info.plist file.
If you don't want to use the option above and you are using SwiftLinkPreview
for services of your knowledge, you can whitelist them on Info.plist file as well. You can read more about it here, here and here.
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.
Tests
Feel free to fork this repo and add URLs on SwiftLinkPreviewTests/URLs.swift to test URLs and help improving this lib. The more URLs the better the reliability.
Information and Contact
Developed by @LeonardoCardoso.
Contact me either by Twitter @leocardz or emailing me to contact@leocardz.com.
Related Projects
License
The MIT License (MIT)