- Website: https://screenshotbase.com
- API Docs: https://screenshotbase.com/docs/
Add to your Podfile:
pod 'Screenshotbase', :git => 'https://github.com/martechdev/screenshotbase-ios.git', :tag => '0.1.0'
Then run:
pod install
import Screenshotbase
let client = ScreenshotbaseClient(configuration: .init(apiKey: "YOUR_API_KEY"))
Task {
do {
let json = try await client.capture(options: [
"url": "https://example.com",
"width": 1280,
"height": 800
])
print(json)
} catch {
print(error)
}
}
For platforms without async/await, use the completion variant:
client.capture(options: ["url": "https://example.com"]) { result in
switch result {
case .success(let json):
print(json)
case .failure(let error):
print(error)
}
}
let pdf = try await client.capture(options: [
"url": "https://example.com/invoice/123",
"format": "pdf",
"pdfBackground": true,
"margin": ["top": "20px", "right": "20px", "bottom": "20px", "left": "20px"]
])
let ready = try await client.capture(options: [
"url": "https://app.example.com/dashboard",
"waitFor": ["selector": "#dashboard-loaded"],
"deviceScaleFactor": 2
])
let full = try await client.capture(options: [
"url": "https://example.com",
"fullPage": true,
"omitBackground": true
])
let authed = try await client.capture(options: [
"url": "https://example.com/private",
"headers": ["Authorization": "Bearer \(token)"]
])
let html = """
<!doctype html><html><body><h1>Hello</h1></body></html>
"""
let fromHtml = try await client.capture(options: [
"html": html,
"width": 800,
"height": 400
])
if let urlString = (try? await client.capture(options: ["url": "https://example.com"]))?["url"] as? String,
let remote = URL(string: urlString) {
let (data, _) = try await URLSession.shared.data(from: remote)
try data.write(to: URL(fileURLWithPath: "/tmp/screenshot.png"))
}
struct ScreenshotView: View {
@State private var image: UIImage?
let client = ScreenshotbaseClient(configuration: .init(apiKey: "YOUR_API_KEY"))
var body: some View {
Group {
if let image = image { Image(uiImage: image).resizable().scaledToFit() }
else { ProgressView() }
}
.task {
do {
if let urlString = try await client.capture(options: ["url": "https://apple.com"]) ["url"] as? String,
let remote = URL(string: urlString) {
let (data, _) = try await URLSession.shared.data(from: remote)
image = UIImage(data: data)
}
} catch { print(error) }
}
}
}
MIT