Camera Recording in Swift & PixelKit

First make sure to check out Getting started with PixelKit.

To get access to the camera we first need permission. Add NSCameraUsageDescription to the app’s Info.plist.

Then to get the camera feed going add this to your viewDidLoad:

let camera = CameraPIX()

Now create a rec pix. Add the following code:

let rec = RecPIX()
rec.inPix = camera

To start recording hook up the following to a button:

do {
    try rec.startRec()
} catch {
    print("rec failed:", error)

Then stop the recording and share:

rec.stopRec({ url in
    let activity = UIActivityViewController(activityItems: [url], 
                                            applicationActivities: nil)
    presentViewController(activity, animated: true, completion: {})

If you’d like an image instead, use the following to get an UIImage:

let image = camera.renderedImage

Lämna en kommentar

E-postadressen publiceras inte. Obligatoriska fält är märkta *