Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): reset server path on app updates #1968

Merged
merged 1 commit into from
Sep 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion ios/Capacitor/Capacitor/CAPBridgeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr
return nil
}

if !isDeployDisabled() {
if !isDeployDisabled() && !isNewBinary() {
let defaults = UserDefaults.standard
let persistedPath = defaults.string(forKey: "serverBasePath")
if (persistedPath != nil && !persistedPath!.isEmpty) {
Expand All @@ -113,6 +113,24 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr
return val?.boolValue ?? false
}

func isNewBinary() -> Bool {
if let plist = Bundle.main.infoDictionary {
if let versionCode = plist["CFBundleVersion"] as? String, let versionName = plist["CFBundleShortVersionString"] as? String {
let prefs = UserDefaults.standard
let lastVersionCode = prefs.string(forKey: "lastBinaryVersionCode")
let lastVersionName = prefs.string(forKey: "lastBinaryVersionName")
if !versionCode.isEqual(lastVersionCode) || !versionName.isEqual(lastVersionName) {
prefs.set(versionCode, forKey: "lastBinaryVersionCode")
prefs.set(versionName, forKey: "lastBinaryVersionName")
prefs.set("", forKey: "serverBasePath")
prefs.synchronize()
return true
}
}
}
return false
}

override public func viewDidLoad() {
super.viewDidLoad()
self.becomeFirstResponder()
Expand Down