Screenshot a URL in Swift

Have you or your colleagues ever received an email with a suspicious or unknown URL? Instead of taking an unnecessary risk by clicking the link, why not take a screenshot of it to ensure that it’s safe first? In this tutorial, we will show you to use an API in Swift to fully render a website and generate a PNG screenshot of the full-page — this will allow you to determine the safety level of the site prior to an actual interaction with the URL.

Before we call the screenshot function, you will need the screenshot request parameters:

{
"Url": "string",
"ExtraLoadingWait": 0,
"ScreenshotWidth": 0,
"ScreenshotHeight": 0
}

Once you have the required parameters, we can call the function with the following code:

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

That’s all there is to it! Simple.

--

--

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.