Unverified Commit b8bfdea2 authored by Zach Knox's avatar Zach Knox
Browse files

made it not crash on launch

parent 36618a05
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>XPC!</string> <string>XPC!</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.0</string> <string>1.2</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1</string> <string>43</string>
<key>NSExtension</key> <key>NSExtension</key>
<dict> <dict>
<key>NSExtensionMainStoryboard</key> <key>NSExtensionMainStoryboard</key>
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
92589A6521612D0E0002814F /* TodayViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92589A6421612D0E0002814F /* TodayViewController.swift */; }; 92589A6521612D0E0002814F /* TodayViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92589A6421612D0E0002814F /* TodayViewController.swift */; };
92589A6821612D0E0002814F /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 92589A6621612D0E0002814F /* MainInterface.storyboard */; }; 92589A6821612D0E0002814F /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 92589A6621612D0E0002814F /* MainInterface.storyboard */; };
92589A6C21612D0E0002814F /* TodayWidget.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 92589A6021612D0D0002814F /* TodayWidget.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 92589A6C21612D0E0002814F /* TodayWidget.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 92589A6021612D0D0002814F /* TodayWidget.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
92589A74216132850002814F /* WhatsOpenKit.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 928EC2522160475900D8F9FE /* WhatsOpenKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 92589A752162DBF20002814F /* WhatsOpenKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 928EC2522160475900D8F9FE /* WhatsOpenKit.framework */; };
9259134520784D66002E50B1 /* SelectOneDefaultTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9259134420784D66002E50B1 /* SelectOneDefaultTableViewController.swift */; }; 9259134520784D66002E50B1 /* SelectOneDefaultTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9259134420784D66002E50B1 /* SelectOneDefaultTableViewController.swift */; };
9265F3A11F2969E500A54A21 /* SettingTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9265F3A01F2969E500A54A21 /* SettingTableViewCell.swift */; }; 9265F3A11F2969E500A54A21 /* SettingTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9265F3A01F2969E500A54A21 /* SettingTableViewCell.swift */; };
9265F3A31F2C0B1500A54A21 /* AboutScreenViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9265F3A21F2C0B1500A54A21 /* AboutScreenViewController.swift */; }; 9265F3A31F2C0B1500A54A21 /* AboutScreenViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9265F3A21F2C0B1500A54A21 /* AboutScreenViewController.swift */; };
...@@ -123,16 +123,6 @@ ...@@ -123,16 +123,6 @@
name = "Embed App Extensions"; name = "Embed App Extensions";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
92589A732161327A0002814F /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
92589A74216132850002814F /* WhatsOpenKit.framework in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
928EC2602160495800D8F9FE /* Embed Frameworks */ = { 928EC2602160495800D8F9FE /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase; isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
...@@ -229,6 +219,7 @@ ...@@ -229,6 +219,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
92589A752162DBF20002814F /* WhatsOpenKit.framework in Frameworks */,
92589A6221612D0D0002814F /* NotificationCenter.framework in Frameworks */, 92589A6221612D0D0002814F /* NotificationCenter.framework in Frameworks */,
F818083D0B4F94441442C5C1 /* Pods_TodayWidget.framework in Frameworks */, F818083D0B4F94441442C5C1 /* Pods_TodayWidget.framework in Frameworks */,
); );
...@@ -314,13 +305,13 @@ ...@@ -314,13 +305,13 @@
9255C5A921556E410094C947 /* WhatsOpenKit */ = { 9255C5A921556E410094C947 /* WhatsOpenKit */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
928EC26621611E5900D8F9FE /* DatabaseController.swift */,
CD3C97481DC18AB300A84434 /* DownloadController.swift */,
9270A4DC1EC0010300DFBDA3 /* Filters.swift */, 9270A4DC1EC0010300DFBDA3 /* Filters.swift */,
CD763A791DE24EF100ADFD6B /* Model.swift */,
CD763A7D1DE253B900ADFD6B /* Utilities.swift */, CD763A7D1DE253B900ADFD6B /* Utilities.swift */,
9255C5AA21556E410094C947 /* WhatsOpenKit.h */, 9255C5AA21556E410094C947 /* WhatsOpenKit.h */,
CD763A791DE24EF100ADFD6B /* Model.swift */,
CD3C97481DC18AB300A84434 /* DownloadController.swift */,
9255C5AB21556E410094C947 /* Info.plist */, 9255C5AB21556E410094C947 /* Info.plist */,
928EC26621611E5900D8F9FE /* DatabaseController.swift */,
); );
path = WhatsOpenKit; path = WhatsOpenKit;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -482,7 +473,6 @@ ...@@ -482,7 +473,6 @@
92589A5C21612D0D0002814F /* Sources */, 92589A5C21612D0D0002814F /* Sources */,
92589A5D21612D0D0002814F /* Frameworks */, 92589A5D21612D0D0002814F /* Frameworks */,
92589A5E21612D0D0002814F /* Resources */, 92589A5E21612D0D0002814F /* Resources */,
92589A732161327A0002814F /* CopyFiles */,
B6B1E55889B1F6531E83B1F6 /* [CP] Copy Pods Resources */, B6B1E55889B1F6531E83B1F6 /* [CP] Copy Pods Resources */,
); );
buildRules = ( buildRules = (
......
...@@ -25,10 +25,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -25,10 +25,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
#if APPSTORE #if APPSTORE
Fabric.with([Crashlytics.self]) Fabric.with([Crashlytics.self])
migrateDefaults()
#endif #endif
let defaults = WOPDatabaseController.getDefaults() let defaults = WOPDatabaseController.getDefaults()
initAlerts(defaults) initAlerts(defaults)
initCampuses(defaults) initCampuses(defaults)
if defaults.value(forKey: "mapsApp") == nil { if defaults.value(forKey: "mapsApp") == nil {
...@@ -68,6 +71,23 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -68,6 +71,23 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
} }
} }
func migrateDefaults() {
let oldDefaults = UserDefaults.standard
if oldDefaults.integer(forKey: "migrated") <= 0 && oldDefaults.value(forKey: "mapsApp") != nil {
// migrating from a pre 1.2 release
let defaults = WOPDatabaseController.getDefaults()
defaults.set(oldDefaults.string(forKey: "mapsApp"), forKey: "mapsApp")
defaults.set(oldDefaults.dictionary(forKey: "alerts"), forKey: "alerts")
defaults.set(oldDefaults.dictionary(forKey: "campuses"), forKey: "campuses")
defaults.set(oldDefaults.array(forKey: "favorites") ?? [], forKey: "favorites")
defaults.set(1, forKey: "migrated")
} else if oldDefaults.value(forKey: "mapsApp") != nil {
// if initial launch, consider it migrated
let defaults = WOPDatabaseController.getDefaults()
defaults.set(1, forKey: "migrated")
}
}
func initAlerts(_ defaults: UserDefaults) { func initAlerts(_ defaults: UserDefaults) {
let alerts = defaults.dictionary(forKey: "alerts") let alerts = defaults.dictionary(forKey: "alerts")
if alerts == nil { if alerts == nil {
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
</dict> </dict>
</array> </array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>40</string> <string>43</string>
<key>Fabric</key> <key>Fabric</key>
<dict> <dict>
<key>APIKey</key> <key>APIKey</key>
......
...@@ -37,7 +37,7 @@ class DetailViewButtonsViewController: UIViewController { ...@@ -37,7 +37,7 @@ class DetailViewButtonsViewController: UIViewController {
} }
@IBAction func getDirections(_ sender: Any) { @IBAction func getDirections(_ sender: Any) {
let appToUse = UserDefaults.standard.value(forKey: "mapsApp") as? String let appToUse = WOPDatabaseController.getDefaults().value(forKey: "mapsApp") as? String
if appToUse == "Google Maps" && UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!) { if appToUse == "Google Maps" && UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!) {
if let url = URL(string: "comgooglemaps://?q=\((facility.facilityLocation?.coordinates?.coords?.last)!)),\((facility.facilityLocation?.coordinates?.coords?.first)!)") { if let url = URL(string: "comgooglemaps://?q=\((facility.facilityLocation?.coordinates?.coords?.last)!)),\((facility.facilityLocation?.coordinates?.coords?.first)!)") {
...@@ -103,7 +103,7 @@ class DetailViewButtonsViewController: UIViewController { ...@@ -103,7 +103,7 @@ class DetailViewButtonsViewController: UIViewController {
directionsButton.backgroundColor = #colorLiteral(red: 0, green: 0.4793452024, blue: 0.9990863204, alpha: 1) directionsButton.backgroundColor = #colorLiteral(red: 0, green: 0.4793452024, blue: 0.9990863204, alpha: 1)
directionsButton.layer.cornerRadius = 10 directionsButton.layer.cornerRadius = 10
let appToUse = UserDefaults.standard.value(forKey: "mapsApp") as? String let appToUse = WOPDatabaseController.getDefaults().value(forKey: "mapsApp") as? String
if appToUse == "Google Maps" && UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!) { if appToUse == "Google Maps" && UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!) {
directionsButton.setTitle("View in Google Maps", for: .normal) directionsButton.setTitle("View in Google Maps", for: .normal)
} }
......
...@@ -210,7 +210,6 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate, ...@@ -210,7 +210,6 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
@objc func toDetailFromURL(_ notification: Notification) { @objc func toDetailFromURL(_ notification: Notification) {
let facilityEncoded = notification.userInfo!["facility"] as? String let facilityEncoded = notification.userInfo!["facility"] as? String
let facilityDecoded = facilityEncoded?.removingPercentEncoding let facilityDecoded = facilityEncoded?.removingPercentEncoding
print(facilityDecoded)
let facility = realm.objects(WOPFacilitiesModel.self)[0].facilities.filter(NSPredicate(format: "facilityName = \"" + (facilityDecoded)! + "\"")).first let facility = realm.objects(WOPFacilitiesModel.self)[0].facilities.filter(NSPredicate(format: "facilityName = \"" + (facilityDecoded)! + "\"")).first
if(facility == nil) { if(facility == nil) {
return // don't do anything return // don't do anything
...@@ -288,13 +287,14 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate, ...@@ -288,13 +287,14 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
func begForReviews(_ dismissed: Bool) { func begForReviews(_ dismissed: Bool) {
// MARK - Begging for App Reviews // MARK - Begging for App Reviews
let prompt = UserDefaults.standard.integer(forKey: "reviewPrompt") let defaults = WOPDatabaseController.getDefaults()
let prompt = defaults.integer(forKey: "reviewPrompt")
if(arc4random_uniform(100) > 92 && prompt >= 4) { if(arc4random_uniform(100) > 92 && prompt >= 4) {
SKStoreReviewController.requestReview() SKStoreReviewController.requestReview()
UserDefaults.standard.set(0, forKey: "reviewPrompt") defaults.set(0, forKey: "reviewPrompt")
} }
else { else {
UserDefaults.standard.set(prompt + 1, forKey: "reviewPrompt") defaults.set(prompt + 1, forKey: "reviewPrompt")
} }
} }
...@@ -350,7 +350,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate, ...@@ -350,7 +350,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
filteredFacilities = filters.applyFiltersOnFacilities(facilitiesArray) filteredFacilities = filters.applyFiltersOnFacilities(facilitiesArray)
let defaults = UserDefaults.standard let defaults = WOPDatabaseController.getDefaults()
// Campuses // Campuses
...@@ -524,7 +524,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate, ...@@ -524,7 +524,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
func updateFiltersLists() { func updateFiltersLists() {
// Add locations and categories to filters // Add locations and categories to filters
let defaults = UserDefaults.standard let defaults = WOPDatabaseController.getDefaults()
var campusFilters = defaults.dictionary(forKey: "campuses") as! [String: Bool]? var campusFilters = defaults.dictionary(forKey: "campuses") as! [String: Bool]?
for f in facilitiesArray { for f in facilitiesArray {
if(!filters.onlyFromCategories.keys.contains((f.category?.categoryName)!)) { if(!filters.onlyFromCategories.keys.contains((f.category?.categoryName)!)) {
......
...@@ -7,13 +7,14 @@ ...@@ -7,13 +7,14 @@
// //
import UIKit import UIKit
import WhatsOpenKit
class SelectOneDefaultTableViewController: UITableViewController { class SelectOneDefaultTableViewController: UITableViewController {
// Passing functions rather than direct objects to make this class reusable // Passing functions rather than direct objects to make this class reusable
var options: [String]! var options: [String]!
var defaultKey: String! var defaultKey: String!
let defaults = UserDefaults.standard let defaults = WOPDatabaseController.getDefaults()
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
......
...@@ -88,7 +88,7 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr ...@@ -88,7 +88,7 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
cell.textLabel!.text = "Select Maps App" cell.textLabel!.text = "Select Maps App"
cell.textLabel?.font = UIFont.preferredFont(forTextStyle: .body) cell.textLabel?.font = UIFont.preferredFont(forTextStyle: .body)
cell.detailTextLabel?.font = UIFont.preferredFont(forTextStyle: .footnote) cell.detailTextLabel?.font = UIFont.preferredFont(forTextStyle: .footnote)
cell.detailTextLabel?.text = UserDefaults.standard.value(forKey: "mapsApp") as? String cell.detailTextLabel?.text = WOPDatabaseController.getDefaults().value(forKey: "mapsApp") as? String
cell.accessoryType = .disclosureIndicator cell.accessoryType = .disclosureIndicator
return cell return cell
} }
......
...@@ -32,7 +32,7 @@ public class WOPDatabaseController { ...@@ -32,7 +32,7 @@ public class WOPDatabaseController {
// If appstore, use an app group for the DB // If appstore, use an app group for the DB
#if APPSTORE #if APPSTORE
let fileURL = FileManager.default let fileURL = FileManager.default
.containerURL(forSecurityApplicationGroupIdentifier: "group.edu.gmu.srct.whatsopen") .containerURL(forSecurityApplicationGroupIdentifier: "group.edu.gmu.srct.whatsopen")?.appendingPathComponent("Library/Application Support/", isDirectory: true)
config.fileURL = fileURL!.deletingLastPathComponent().appendingPathComponent("whatsopen.realm") config.fileURL = fileURL!.deletingLastPathComponent().appendingPathComponent("whatsopen.realm")
#endif #endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment