Nosmai  Effects Nosmai  Moderation Nosmai Try-ons coming soon
Docs menu iOS
How-to guide

Manage the camera lifecycle on iOS

Keep one iOS camera owner, pause and resume capture with screen state, switch lenses safely, and release the preview when leaving.

Platform iOS SDK version 3.0.4 Updated Aug 22, 2026 Time 6 min

Prerequisites

  • A working iOS quickstart
  • One view controller that owns the attached Nosmai preview
  • No second AVCaptureSession competing for the camera

Pause and resume capture

Pause for a temporary interruption and resume the same camera session when the screen becomes active again:

NosmaiCamera *camera = [NosmaiCore shared].camera;
[camera pauseCapture];
[camera resumeCapture];

Serialize these calls on the main thread. Do not resume after the controller has detached its preview.

Switch the camera

Disable repeated switch taps until the Boolean result returns:

BOOL switched = [[NosmaiCore shared].camera switchCamera];
if (!switched) {
  // Keep the current camera and re-enable the control.
}

Use switchToPosition: when product state requires an explicit front or back position rather than a toggle.

Release the screen owner

Stop capture before detaching the preview. Call global cleanup only when the application no longer needs the shared SDK state.

NosmaiCamera *camera = [NosmaiCore shared].camera;
[camera stopCapture];
[camera detachFromView];

Verify it worked

Switch front to back and back to front, background and foreground the app, then leave and reopen the screen ten times. The camera indicator must turn off after release and only one preview may be active.

Common errors

SymptomCauseFix
Switch returns NOCapture is not ready or another transition is activeKeep the current position and retry only after the camera is stable
Camera indicator stays on after navigationCapture stopped without detaching the previewCall stopCapture and detachFromView from the screen owner
Reopened preview is blackAn old controller still owns the camera or resume raced with teardownAwait screen teardown and keep all camera mutations on the main thread

Next steps

References

Was this page helpful?

Your response helps us prioritize documentation improvements.

Nosmai

An AR and AI company. Founded on the idea that the next decade of software will be visual, and that the tools for it should be within reach of anyone building.

Newsletter

Product updates and release notes. No spam.

© 2026 nosmai, inc · all rights reserved