-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSystemApplicationManager.swift
72 lines (57 loc) · 2.55 KB
/
SystemApplicationManager.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
//
// ApplicationManager.swift
// AppExplorer
//
// Created by Cardasis, Jonathan (J.) on 7/13/16.
// Copyright © 2016 Cardasis, Jonathan (J.). All rights reserved.
//
import Foundation
class SystemApplicationManager: NSObject {
static let sharedManager = SystemApplicationManager()
fileprivate var workspace: LSApplicationWorkspace?
override init() {
workspace = LSApplicationWorkspace.defaultWorkspace() as? LSApplicationWorkspace
}
func allInstalledApplications() -> [SystemApplication]{
guard let workspace = workspace else { //protect
return []
}
var applications = [SystemApplication]()
let installedApplicationProxies = workspace.allInstalledApplications() as! [LSApplicationProxy]
for applicationProxy in installedApplicationProxies {
let bundleIdentifier = applicationProxy.bundleIdentifier
let appIcon = self.applicationIconImageForBundleIdentifier(bundleIdentifier!)
/* Create and map a system application object to LSApplicationProxys variables */
let app = SystemApplication()
app.map(bundleID: bundleIdentifier,
name: applicationProxy.localizedName,
version: applicationProxy.shortVersionString,
executableName: applicationProxy.bundleExecutable,
type: applicationProxy.applicationType,
signerIdentity: applicationProxy.signerIdentity,
applicationPath: applicationProxy.dataContainerURL,
backgroundModes: applicationProxy.uiBackgroundModes as? [String],
icon: appIcon
)
applications.append(app)
}
return applications
}
@discardableResult func openApplication(_ app: SystemApplication) -> Bool {
if let workspace = workspace {
return workspace.openApplication(withBundleID: app.bundleID)
}
return false
}
@discardableResult func openApplication(bundleID: String) -> Bool {
if let workspace = workspace {
return workspace.openApplication(withBundleID: bundleID)
}
return false
}
func applicationIconImageForBundleIdentifier(_ bundleID: String) -> UIImage?{
//Format of 2 will return a 62x62 image
return UIImage._applicationIconImage(forBundleIdentifier: bundleID, format: 2
, scale: Double(UIScreen.main.scale)) as? UIImage
}
}