-
Notifications
You must be signed in to change notification settings - Fork 739
/
iosutil.go
84 lines (70 loc) · 1.96 KB
/
iosutil.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package iosutil
import (
"errors"
"strconv"
"strings"
)
// Version specifies the version of an iOS device.
type Version struct {
Major int
Minor int
}
// ParseVersion parses the major.minor version for an iOS device.
func ParseVersion(v string) (Version, error) {
parts := strings.Split(v, ".")
if len(parts) < 2 || len(parts) > 3 {
return Version{}, errors.New("expected either major.minor or major.minor.patch format")
}
major, err := strconv.Atoi(parts[0])
if err != nil {
return Version{}, errors.New("major version is not an integer")
}
minor, err := strconv.Atoi(parts[1])
if err != nil {
return Version{}, errors.New("minor version is not an integer")
}
version := Version{
Major: major,
Minor: minor,
}
return version, nil
}
// Equal returns true if the iOS device version is equal to the desired major and minor version, using semantic versioning.
func (v Version) Equal(major, minor int) bool {
if v.Major == major {
return v.Minor == minor
}
return false
}
// EqualOrGreater returns true if the iOS device version is equal or greater to the desired version, using semantic versioning.
func (v Version) EqualOrGreater(major, minor int) bool {
if v.Major == major {
return v.Minor >= minor
}
return v.Major > major
}
// VersionClassification describes iOS version classifications which are important to Prebid Server.
type VersionClassification int
// Values of VersionClassification.
const (
VersionUnknown VersionClassification = iota
Version140
Version141
Version142OrGreater
)
// DetectVersionClassification detects the iOS version classification.
func DetectVersionClassification(v string) VersionClassification {
// semantic versioning comparison second. parsing required.
if iosVersion, err := ParseVersion(v); err == nil {
if iosVersion.Equal(14, 0) {
return Version140
}
if iosVersion.Equal(14, 1) {
return Version141
}
if iosVersion.EqualOrGreater(14, 2) {
return Version142OrGreater
}
}
return VersionUnknown
}