-
Notifications
You must be signed in to change notification settings - Fork 27
/
AppInfo.swift
86 lines (75 loc) · 3.82 KB
/
AppInfo.swift
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
85
86
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import Foundation
open class AppInfo {
/// Return the main application bundle. If this is called from an extension, the containing app bundle is returned.
open static var applicationBundle: Bundle {
let bundle = Bundle.main
switch bundle.bundleURL.pathExtension {
case "app":
return bundle
case "appex":
// .../Client.app/PlugIns/SendTo.appex
return Bundle(url: bundle.bundleURL.deletingLastPathComponent().deletingLastPathComponent())!
default:
fatalError("Unable to get application Bundle (Bundle.main.bundlePath=\(bundle.bundlePath))")
}
}
open static var displayName: String {
return applicationBundle.object(forInfoDictionaryKey: "CFBundleDisplayName") as! String
}
open static var appVersion: String {
return applicationBundle.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
}
open static var buildNumber: String {
return applicationBundle.object(forInfoDictionaryKey: String(kCFBundleVersionKey)) as! String
}
open static var majorAppVersion: String {
return appVersion.components(separatedBy: ".").first!
}
/// Return the shared container identifier (also known as the app group) to be used with for example background
/// http requests. It is the base bundle identifier with a "group." prefix.
open static var sharedContainerIdentifier: String {
var bundleIdentifier = baseBundleIdentifier
if bundleIdentifier == "org.mozilla.ios.FennecEnterprise" {
// Bug 1373726 - Base bundle identifier incorrectly generated for Nightly builds
// This can be removed when we are able to fix the app group in the developer portal
bundleIdentifier = "org.mozilla.ios.Fennec.enterprise"
}
return "group." + bundleIdentifier
}
/// Return the keychain access group.
open static func keychainAccessGroupWithPrefix(_ prefix: String) -> String {
var bundleIdentifier = baseBundleIdentifier
if bundleIdentifier == "org.mozilla.ios.FennecEnterprise" {
// Bug 1373726 - Base bundle identifier incorrectly generated for Nightly builds
// This can be removed when we are able to fix the app group in the developer portal
bundleIdentifier = "org.mozilla.ios.Fennec.enterprise"
}
return prefix + "." + bundleIdentifier
}
/// Return the base bundle identifier.
///
/// This function is smart enough to find out if it is being called from an extension or the main application. In
/// case of the former, it will chop off the extension identifier from the bundle since that is a suffix not part
/// of the *base* bundle identifier.
open static var baseBundleIdentifier: String {
let bundle = Bundle.main
let packageType = bundle.object(forInfoDictionaryKey: "CFBundlePackageType") as! String
let baseBundleIdentifier = bundle.bundleIdentifier!
if packageType == "XPC!" {
let components = baseBundleIdentifier.components(separatedBy: ".")
return components[0..<components.count-1].joined(separator: ".")
}
return baseBundleIdentifier
}
// Return the MozWhatsNewTopic key from the Info.plist
open static var whatsNewTopic: String? {
return Bundle.main.object(forInfoDictionaryKey: "MozWhatsNewTopic") as? String
}
// Return whether the currently executing code is running in an Application
open static var isApplication: Bool {
return Bundle.main.object(forInfoDictionaryKey: "CFBundlePackageType") as! String == "APPL"
}
}