[#102][#101] Loading view error handling, Load pairingfile from docs, bundle, plist (#112)

* refs #102 load pairingfile from docs, bundle,plist

tries Documents/ALTPairingFile.plist, then app bundle resources ALTPairingFile.plist, finally Info.plist with non default value

Signed-off-by: Joseph Mattello <mail@joemattiello.com>

* refs #102 change plist to mobiledevicepairing

fixes xcode compiling .plist resources

Signed-off-by: Joseph Mattello <mail@joemattiello.com>

Signed-off-by: Joseph Mattello <mail@joemattiello.com>
This commit is contained in:
Joe Mattiello
2022-11-08 14:15:09 -05:00
committed by GitHub
parent 84f58efc17
commit 84e2faf8a8
7 changed files with 95 additions and 8 deletions

View File

@@ -37,16 +37,57 @@ class LaunchViewController: RSTLaunchViewController
override func viewDidLoad()
{
defer {
// Create destinationViewController now so view controllers can register for receiving Notifications.
self.destinationViewController = self.storyboard!.instantiateViewController(withIdentifier: "tabBarController") as! TabBarController
}
super.viewDidLoad()
start_em_proxy(bind_addr: "127.0.0.1:51820")
start_em_proxy(bind_addr: Consts.Proxy.serverURL)
let pf = Bundle.main.object(forInfoDictionaryKey: "ALTPairingFile") as? String
guard let pf = fetchPairingFile() else {
displayError("ALTPairingFile not found.")
return
}
set_usbmuxd_socket()
start_minimuxer(pairing_file: pf.unsafelyUnwrapped)
start_minimuxer(pairing_file: pf)
auto_mount_dev_image()
}
func fetchPairingFile() -> String? {
let filename = "ALTPairingFile.mobiledevicepairing"
let fm = FileManager.default
let documentsPath = fm.documentsDirectory.appendingPathComponent("/\(filename)")
if fm.fileExists(atPath: documentsPath.path), let contents = try? String(contentsOf: documentsPath), !contents.isEmpty {
print("Loaded ALTPairingFile from \(documentsPath.path)")
return contents
} else if
let appResourcePath = Bundle.main.url(forResource: "ALTPairingFile", withExtension: "mobiledevicepairing"),
fm.fileExists(atPath: appResourcePath.path),
let data = fm.contents(atPath: appResourcePath.path),
let contents = String(data: data, encoding: .utf8),
!contents.isEmpty {
print("Loaded ALTPairingFile from \(appResourcePath.path)")
return contents
} else if let plistString = Bundle.main.object(forInfoDictionaryKey: "ALTPairingFile") as? String, !plistString.isEmpty, !plistString.contains("insert pairing file here"){
print("Loaded ALTPairingFile from Info.plist")
return plistString
} else {
return nil
}
}
func displayError(_ msg: String) {
let label = UILabel()
label.text = msg
label.textColor = .refreshRed
label.sizeToFit()
// Create destinationViewController now so view controllers can register for receiving Notifications.
self.destinationViewController = self.storyboard!.instantiateViewController(withIdentifier: "tabBarController") as! TabBarController
self.view.addSubview(label)
NSLayoutConstraint.activate([
label.centerXAnchor.constraint(equalTo: view.centerXAnchor),
label.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])
}
}