Swiftpack.co - placidapp/placid-ios as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by placidapp.
placidapp/placid-ios 1.0.1
Use on-device image generation based on dynamic templates with the official Placid SDK for iOS
⭐️ 3
🕓 1 year ago
iOS
.package(url: "https://github.com/placidapp/placid-ios.git", from: "1.0.1")

Placid.app iOS SDK

Placid iOS SDK

Generate custom share images on-device

Placid is a toolkit for creative automation. It lets you generate images with dynamic content from custom templates - e.g. for personalized share visuals. The Placid iOS SDK offers native, on-device image generation for your apps.

  • Offline, on-device image generation
  • Custom templates for on-brand visuals
  • Drag & drop template editor
  • Dynamic content layers
  • Auto-resizing for text and images
  • Unlimited generated images
  • Dynamic in-app previews

➡️ Learn more about the Placid Mobile SDK


⚙️ Requirements

  • iOS 13.0

📦️ Installation

Swift Package Manager

To integrate the Placid SDK into your Xcode project using Swift Package Manager, specify it in the dependencies of your Package.swift:

// swift-tools-version:5.3
import PackageDescription
...
dependencies: [
    .package(url: "https://github.com/placidapp/placid-ios.git", .upToNextMajor(from: "1.0.1"))
]
...

:warning: The SDK has dependencies on binary frameworks, so you have to use a version higher than 5.3 of your Swift Tools

CocoaPods

To integrate Placid into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'Placid'

Carthage

To integrate Placid into your Xcode project using Carthage, specify it in your Cartfile:

binary "https://raw.githubusercontent.com/placidapp/placid-ios/master/Placid.json"

Manually

If you prefer to integrate Placid manually instead of using a Dependency Manager, download the latest Placid.xcframwork and add it to your project.

✨ Usage

Setup on placid.app

  1. Register on placid.app (✅ free trial)
  2. Create a project and add the Placid mobile integration
  3. Add a template
  4. Add a mobile license in your project settings
  5. Download your template(s) to use with the SDK

Configuration

Configure the Placid SDK in your AppDelegate by providing the URL to your mobile templates package downloaded from the Placid web app.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    do {
	try PlacidSDK.configure(withLicenseKey: "your-placid-license-key", templateURL: Bundle.main.url(forResource: "templates", withExtension: "placid"))
    } catch {
        print(error.localizedDescription)
    }
}

Retrieve Templates

Templates can be retrieved via their unique identifier (as found in the Placid web app). If the template is not found, this method will return nil.

let template = PlacidSDK.template(withIdentifier: "template-identifier")

Preload Templates

For faster rendering it is recommended to preload a template as soon as it is accessed.

template.preload()

Modify Layer Data

You can modify the content and appearance of dynamic layers in your template.

:warning: Use the layer names as specified in the template editor, otherwise the layer will be ignored.

Text

let textLayer = template.textLayer(named: "title")
textLayer.text = "A new title"
textLayer.textColor = UIColor.red

Images

let image = UIImage(named: "avatar")!
let pictureLayer = template.pictureLayer(named: "avatar")
pictureLayer.image = image

Rectangles

let rectangleLayer = template.rectangleLayer(named: "rect")
rectangleLayer.backgroundColor = UIColor.red
rectangleLayer.borderColor = UIColor.blue

Browser Frames

let browserFrameLayer = template.browserFrameLayer(named: "browser")
browserFrameLayer.url = browserURL

General Properties

These properties are supported by all layer types.

let layer = template.textLayer(named: "title")
layer.isHidden = false
layer.origin = .zero
layer.size = CGSize(width: 100, height: 50)

The mobile SDK supports the same layers and properties as the Placid REST API, so have a look for the full set of supported functions and properties.

Render Images

Once all data is added to the template, it can be rendered to a native image. Use the rendered image in your UIImageView or Image for dynamic in-app previews or pass it along for social sharing.

template.renderImage(completion: { [weak self] image in
	// use the image here
})

Or via async function:

let image = await template.renderImage()

💬 Support

For bug reports, please create a new Issue right here on Github. Otherwise have a look at our Help section.

GitHub

link
Stars: 3
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.0.1
1 year ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics