Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EC512] Swift port #290

Open
zippy1978 opened this issue Apr 29, 2024 · 0 comments
Open

[EC512] Swift port #290

zippy1978 opened this issue Apr 29, 2024 · 0 comments
Assignees
Labels
🗃️ rule rule improvment or rule development or bug

Comments

@zippy1978
Copy link
Contributor

Swift port to the existing EC512 rule:

Most iOS devices come equipped with a variety of sensors that measure motion, orientation, and various environmental conditions. Additionally, these devices include advanced sensors such as the image sensor (commonly referred to as the Camera) and the geo-positioning sensor (commonly referred to as GPS).

The common point of all these sensors is that they are power-intensive while in use. A typical issue arises when these sensors continue to process data unnecessarily after the application enters an idle state, like when it is backgrounded or the user stops interacting with it.

As a result, calls to manage these sensors must be carefully paired: AVCaptureSession.startRunning() and AVCaptureSession.stopRunning(). Failure to properly manage these calls can lead to significant battery drain within a few hours.

Noncompliant Code Example

import AVFoundation

class CameraManager {
    var captureSession: AVCaptureSession?

    func activateCamera() {
        captureSession = AVCaptureSession()
        captureSession?.startRunning()  // Camera starts capturing
        // Missing corresponding stopRunning
    }
}

Compliant Code Example

import AVFoundation

class CameraManager {
    var captureSession: AVCaptureSession?

    func activateCamera() {
        captureSession = AVCaptureSession()
        captureSession?.startRunning()  // Camera starts capturing
    }

    func deactivateCamera() {
        captureSession?.stopRunning()  // Camera stops capturing
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗃️ rule rule improvment or rule development or bug
Projects
None yet
Development

No branches or pull requests

1 participant