SkillAgentSearch skills...

LinkPreviewCustomAction

Custom iOS 9 preview actions for link previews in iOS webviews

Install / Use

/learn @Instapaper/LinkPreviewCustomAction
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

LinkPreviewCustomActions

In iOS 9, UIWebView and WKWebView can support 3D touches on links to preview the linked URL with SFSafariViewController by setting the allowsLinkPreview to YES on the web view. However, there isn't currently a way to provide a set of custom actions to SFSafariViewController and, as such, the UIPreviewActionItem list is always "Open", "Add to Reading List", and "Copy".

This project is a proof-of-concept to provide custom UIPreviewActionItems to link previews using SFSafariViewController. The approach is somewhat convoluted because the hooks for previewing the link are within the web views, and the developer is never given hooks to provide their own data. The solution is to create a category on SFSafariViewController, override - (NSArray<id<UIPreviewActionItem>> *)previewActionItems instance method, and pull the URL from the SFSafariViewController's delegate. The SFSafariViewControllerDelegate is an instance of DDURLPreviewAction, which responds to @selector(url). The code is written in such a way to not use private APIs, and fail gracefully should the internal workings change in a future release.

Here's a screenshot of the result:

screenshot

Related Skills

View on GitHub
GitHub Stars39
CategoryDevelopment
Updated5y ago
Forks1

Languages

Objective-C

Security Score

60/100

Audited on Nov 19, 2020

No findings