-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #302 from green-code-initiative/fix/mobile-rules-s…
…orting
- Loading branch information
Showing
24 changed files
with
52 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
"environment", | ||
"ecocode", | ||
"android", | ||
"ios", | ||
"eco-design" | ||
], | ||
"ecoScore": "0.6", | ||
|
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
"environment", | ||
"ecocode", | ||
"android", | ||
"ios", | ||
"eco-design" | ||
], | ||
"ecoScore": "0.4", | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
"environment", | ||
"ecocode", | ||
"android", | ||
"ios", | ||
"eco-design" | ||
], | ||
"ecoScore": "1.0", | ||
|
File renamed without changes.
File renamed without changes.
13 changes: 4 additions & 9 deletions
13
ecocode-rules-specifications/src/main/rules/EC522/swift/EC522.asciidoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,10 @@ | ||
Location awareness is one of the most popular features used by apps. | ||
To avoid draining the battery, an iOS device adapt its brightness to the environment . | ||
|
||
By default, standard location updates run with the best accuracy level, but unless your app really needs to know the user’s position within a few meters, this level of accuracy isn't needed. | ||
Hence, keeping forcing the screen brightness on should be avoided, unless it is absolutely necessary. If so, developers typically force the Brightness to 1 with `UIScreen.main.brightness = a float`. | ||
|
||
Requesting higher accuracy than you need causes the system to power up additional hardware and waste power for unnecessary precision. You can specify a degree of accuracy by setting the `CLLocationManager#desiredAccuracy` property. | ||
|
||
Also, setting the `CLLocationManager#activityType` property will let the system knows what type of location activity your app is performing and helps it determine the most appropriate time to perform location updates. Finally, if your app just needs a quick fix on the user’s location, it’s best to call the `CLLocationManager#requestLocation` method, that will deliver a single location update. | ||
|
||
## Compliant Code Example | ||
## Noncompliant Code Example | ||
|
||
```swift | ||
let manager = CLLocationManager() | ||
manager.desiredAccuracy = 2 | ||
UIScreen.main.brightness = CGFloat(0.3) | ||
``` | ||
|
10 changes: 0 additions & 10 deletions
10
ecocode-rules-specifications/src/main/rules/EC523/swift/EC523.asciidoc
This file was deleted.
Oops, something went wrong.
20 changes: 8 additions & 12 deletions
20
ecocode-rules-specifications/src/main/rules/EC524/swift/EC524.asciidoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
Turning on the torch mode programmatically must absolutely be avoided because the flashlight is one of the most energy-intensive component. | ||
Location awareness is one of the most popular features used by apps. | ||
|
||
## Noncompliant Code Example | ||
By default, standard location updates run with the best accuracy level, but unless your app really needs to know the user’s position within a few meters, this level of accuracy isn't needed. | ||
|
||
```swift | ||
AVCaptureTorchMode.on | ||
``` | ||
|
||
or | ||
Requesting higher accuracy than you need causes the system to power up additional hardware and waste power for unnecessary precision. You can specify a degree of accuracy by setting the `CLLocationManager#desiredAccuracy` property. | ||
|
||
```swift | ||
setTorchModeOn(level: Float) | ||
``` | ||
Also, setting the `CLLocationManager#activityType` property will let the system knows what type of location activity your app is performing and helps it determine the most appropriate time to perform location updates. Finally, if your app just needs a quick fix on the user’s location, it’s best to call the `CLLocationManager#requestLocation` method, that will deliver a single location update. | ||
|
||
or | ||
## Compliant Code Example | ||
|
||
```swift | ||
torchMode = .on | ||
let manager = CLLocationManager() | ||
manager.desiredAccuracy = 2 | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
"environment", | ||
"ecocode", | ||
"android", | ||
"ios", | ||
"eco-design" | ||
], | ||
"ecoScore": "0.4", | ||
|
File renamed without changes.
15 changes: 8 additions & 7 deletions
15
...fications/src/main/rules/EC541/EC541.json → ...fications/src/main/rules/EC533/EC533.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
{ | ||
"title": "Idleness: Keep Screen On", | ||
"title": "Location updates pause disabled", | ||
"type": "CODE_SMELL", | ||
"status": "ready", | ||
"remediation": { | ||
"func": "Constant\/Issue", | ||
"constantCost": "20min" | ||
"constantCost": "5min" | ||
}, | ||
"tags": [ | ||
"idleness", | ||
"environment", | ||
"ecocode", | ||
"android", | ||
"eco-design" | ||
"environment", | ||
"sobriety", | ||
"eco-design", | ||
"ios" | ||
], | ||
"ecoScore": "0.4", | ||
"defaultSeverity": "Major" | ||
} | ||
} |
File renamed without changes.
12 changes: 6 additions & 6 deletions
12
...fications/src/main/rules/EC542/EC542.json → ...fications/src/main/rules/EC534/EC534.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
{ | ||
"title": "Idleness: Keep CPU On", | ||
"title": "Motion Sensor Update Rate", | ||
"type": "CODE_SMELL", | ||
"status": "ready", | ||
"remediation": { | ||
"func": "Constant\/Issue", | ||
"constantCost": "1h" | ||
"func": "Constant/Issue", | ||
"constantCost": "5min" | ||
}, | ||
"tags": [ | ||
"idleness", | ||
"sobriety", | ||
"environment", | ||
"ecocode", | ||
"android", | ||
"ios", | ||
"eco-design" | ||
], | ||
"defaultSeverity": "Major" | ||
} | ||
} |
File renamed without changes.
17 changes: 0 additions & 17 deletions
17
ecocode-rules-specifications/src/main/rules/EC545/EC545.json
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
ecocode-rules-specifications/src/main/rules/EC546/EC546.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 19 additions & 18 deletions
37
ecocode-rules-specifications/src/main/rules/EC603/swift/EC603.asciidoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
It's always good that an app has different behavior when device is connected/disconnected to a power station, or has different battery levels. Your app can query the `UIDevice#batteryLevel` and `UIDevice#batteryState` properties at any time to determine the level of charge and the state of the battery. | ||
Animations play a crucial role in creating a dynamic and engaging user interface in iOS applications. Both UIKit and SwiftUI provide powerful tools to create smooth and appealing animations. Developers need to be familiar with various methods and properties to implement animations effectively. | ||
|
||
Your app can also register to receive notifications when the battery level or state changes, using `batteryLevelDidChangeNotification` and `batteryStateDidChangeNotification`. | ||
To ensure animations are used effectively without draining the device's battery, it's important to check for unnecessary animations and optimize them. This can be done by reviewing the use of functions like `withAnimation(::)`, the `animation(_:value:)` view modifier, and the binding’s `animation(_:)` method in SwiftUI, as well as checking the use of UIKit's animation methods. | ||
|
||
## Compliant Code Example | ||
## Noncompliant Code Example UIKit | ||
|
||
```swift | ||
let level = UIDevice.current.batteryLevel | ||
UIView.animate(withDuration:animations:) | ||
UIView.animate(withDuration:animations:completion:) | ||
UIView.animate(withDuration:delay:options:animations:completion:) | ||
UIView.animateKeyframes(withDuration:delay:options:animations:completion:) | ||
UIView.transition(with:duration:options:animations:completion:) | ||
CABasicAnimation | ||
CAKeyframeAnimation | ||
CATransition | ||
``` | ||
|
||
or | ||
## Noncompliant Code Example SwiftUI | ||
|
||
```swift | ||
let state = UIDevice.current.batteryState | ||
``` | ||
|
||
or | ||
|
||
```swift | ||
NotificationCenter.default.addObserver(forName: UIDevice.batteryLevelDidChangeNotification, object: nil, queue: nil) { _ in } | ||
``` | ||
|
||
or | ||
|
||
```swift | ||
NotificationCenter.default.addObserver(forName: UIDevice.batteryStateDidChangeNotification, object: nil, queue: nil) { _ in } | ||
withAnimation | ||
Animation | ||
AnyTransition | ||
.animation(Animation?) | ||
.transition(AnyTransition) | ||
.onAppear(perform:) | ||
.onDisappear(perform:) | ||
``` |