# 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.

> For AI agents: the complete documentation index is at https://nosmai.com/llms/effects.txt

Product: Nosmai Effects
Group: guide
Source: https://nosmai.com/docs/effects/guides/camera/manage-camera-lifecycle/ios/

## Prerequisites

- A working [iOS quickstart](/docs/effects/quickstart/ios/)
- 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:

```objc
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:

```objc
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.

```objc
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

| Symptom | Cause | Fix |
| --- | --- | --- |
| Switch returns `NO` | Capture is not ready or another transition is active | Keep the current position and retry only after the camera is stable |
| Camera indicator stays on after navigation | Capture stopped without detaching the preview | Call `stopCapture` and `detachFromView` from the screen owner |
| Reopened preview is black | An old controller still owns the camera or resume raced with teardown | Await screen teardown and keep all camera mutations on the main thread |

## Next steps

- [Capture a processed photo on iOS](/docs/effects/guides/output/capture-a-photo/ios/)
- [Record processed video on iOS](/docs/effects/guides/output/record-video/ios/)

## References

- [iOS API reference](/docs/effects/reference/api/ios/)
- [iOS platform guide](/docs/effects/platforms/ios/)
