made it not crash on launch

parent 36618a05
......@@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.2</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>43</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionMainStoryboard</key>
......
......@@ -43,7 +43,7 @@
92589A6521612D0E0002814F /* TodayViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92589A6421612D0E0002814F /* TodayViewController.swift */; };
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, ); }; };
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 */; };
9265F3A11F2969E500A54A21 /* SettingTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9265F3A01F2969E500A54A21 /* SettingTableViewCell.swift */; };
9265F3A31F2C0B1500A54A21 /* AboutScreenViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9265F3A21F2C0B1500A54A21 /* AboutScreenViewController.swift */; };
......@@ -123,16 +123,6 @@
name = "Embed App Extensions";
runOnlyForDeploymentPostprocessing = 0;
};
92589A732161327A0002814F /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
92589A74216132850002814F /* WhatsOpenKit.framework in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
928EC2602160495800D8F9FE /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
......@@ -229,6 +219,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
92589A752162DBF20002814F /* WhatsOpenKit.framework in Frameworks */,
92589A6221612D0D0002814F /* NotificationCenter.framework in Frameworks */,
F818083D0B4F94441442C5C1 /* Pods_TodayWidget.framework in Frameworks */,
);
......@@ -314,13 +305,13 @@
9255C5A921556E410094C947 /* WhatsOpenKit */ = {
isa = PBXGroup;
children = (
928EC26621611E5900D8F9FE /* DatabaseController.swift */,
CD3C97481DC18AB300A84434 /* DownloadController.swift */,
9270A4DC1EC0010300DFBDA3 /* Filters.swift */,
CD763A791DE24EF100ADFD6B /* Model.swift */,
CD763A7D1DE253B900ADFD6B /* Utilities.swift */,
9255C5AA21556E410094C947 /* WhatsOpenKit.h */,
CD763A791DE24EF100ADFD6B /* Model.swift */,
CD3C97481DC18AB300A84434 /* DownloadController.swift */,
9255C5AB21556E410094C947 /* Info.plist */,
928EC26621611E5900D8F9FE /* DatabaseController.swift */,
);
path = WhatsOpenKit;
sourceTree = "<group>";
......@@ -482,7 +473,6 @@
92589A5C21612D0D0002814F /* Sources */,
92589A5D21612D0D0002814F /* Frameworks */,
92589A5E21612D0D0002814F /* Resources */,
92589A732161327A0002814F /* CopyFiles */,
B6B1E55889B1F6531E83B1F6 /* [CP] Copy Pods Resources */,
);
buildRules = (
......
......@@ -24,11 +24,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Override point for customization after application launch.
#if APPSTORE
Fabric.with([Crashlytics.self])
Fabric.with([Crashlytics.self])
migrateDefaults()
#endif
let defaults = WOPDatabaseController.getDefaults()
initAlerts(defaults)
initCampuses(defaults)
if defaults.value(forKey: "mapsApp") == nil {
......@@ -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) {
let alerts = defaults.dictionary(forKey: "alerts")
if alerts == nil {
......
......@@ -36,7 +36,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>40</string>
<string>43</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
......
......@@ -37,7 +37,7 @@ class DetailViewButtonsViewController: UIViewController {
}
@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 let url = URL(string: "comgooglemaps://?q=\((facility.facilityLocation?.coordinates?.coords?.last)!)),\((facility.facilityLocation?.coordinates?.coords?.first)!)") {
......@@ -103,7 +103,7 @@ class DetailViewButtonsViewController: UIViewController {
directionsButton.backgroundColor = #colorLiteral(red: 0, green: 0.4793452024, blue: 0.9990863204, alpha: 1)
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://")!) {
directionsButton.setTitle("View in Google Maps", for: .normal)
}
......
......@@ -210,7 +210,6 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
@objc func toDetailFromURL(_ notification: Notification) {
let facilityEncoded = notification.userInfo!["facility"] as? String
let facilityDecoded = facilityEncoded?.removingPercentEncoding
print(facilityDecoded)
let facility = realm.objects(WOPFacilitiesModel.self)[0].facilities.filter(NSPredicate(format: "facilityName = \"" + (facilityDecoded)! + "\"")).first
if(facility == nil) {
return // don't do anything
......@@ -288,13 +287,14 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
func begForReviews(_ dismissed: Bool) {
// 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) {
SKStoreReviewController.requestReview()
UserDefaults.standard.set(0, forKey: "reviewPrompt")
defaults.set(0, forKey: "reviewPrompt")
}
else {
UserDefaults.standard.set(prompt + 1, forKey: "reviewPrompt")
defaults.set(prompt + 1, forKey: "reviewPrompt")
}
}
......@@ -350,7 +350,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
filteredFacilities = filters.applyFiltersOnFacilities(facilitiesArray)
let defaults = UserDefaults.standard
let defaults = WOPDatabaseController.getDefaults()
// Campuses
......@@ -524,7 +524,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
func updateFiltersLists() {
// Add locations and categories to filters
let defaults = UserDefaults.standard
let defaults = WOPDatabaseController.getDefaults()
var campusFilters = defaults.dictionary(forKey: "campuses") as! [String: Bool]?
for f in facilitiesArray {
if(!filters.onlyFromCategories.keys.contains((f.category?.categoryName)!)) {
......
......@@ -7,13 +7,14 @@
//
import UIKit
import WhatsOpenKit
class SelectOneDefaultTableViewController: UITableViewController {
// Passing functions rather than direct objects to make this class reusable
var options: [String]!
var defaultKey: String!
let defaults = UserDefaults.standard
let defaults = WOPDatabaseController.getDefaults()
override func viewDidLoad() {
super.viewDidLoad()
......
......@@ -88,7 +88,7 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
cell.textLabel!.text = "Select Maps App"
cell.textLabel?.font = UIFont.preferredFont(forTextStyle: .body)
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
return cell
}
......
......@@ -32,7 +32,7 @@ public class WOPDatabaseController {
// If appstore, use an app group for the DB
#if APPSTORE
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")
#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