Prerequisites
- A working iOS quickstart
- One view controller that owns the attached Nosmai preview
- No second
AVCaptureSessioncompeting 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
| 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 |