diff --git a/MHacks.xcodeproj/project.pbxproj b/MHacks.xcodeproj/project.pbxproj index d262ea2..33785aa 100644 --- a/MHacks.xcodeproj/project.pbxproj +++ b/MHacks.xcodeproj/project.pbxproj @@ -915,11 +915,11 @@ CODE_SIGN_ENTITLEMENTS = MHacksWatch/MHacksWatch.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 18; + CURRENT_PROJECT_VERSION = 21; DEVELOPMENT_TEAM = 478C74MJ7T; IBSC_MODULE = MHacksWatch_Extension; INFOPLIST_FILE = MHacksWatch/Info.plist; - MARKETING_VERSION = 12.2; + MARKETING_VERSION = 12.4.1; PRODUCT_BUNDLE_IDENTIFIER = com.MPowered.MHacks.watchkitapp; PRODUCT_NAME = MHacks; SDKROOT = watchos; @@ -942,11 +942,11 @@ CODE_SIGN_ENTITLEMENTS = MHacksWatch/MHacksWatch.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 18; + CURRENT_PROJECT_VERSION = 21; DEVELOPMENT_TEAM = 478C74MJ7T; IBSC_MODULE = MHacksWatch_Extension; INFOPLIST_FILE = MHacksWatch/Info.plist; - MARKETING_VERSION = 12.2; + MARKETING_VERSION = 12.4.1; PRODUCT_BUNDLE_IDENTIFIER = com.MPowered.MHacks.watchkitapp; PRODUCT_NAME = MHacks; SDKROOT = watchos; @@ -965,11 +965,11 @@ CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_SUSPICIOUS_MOVES = YES; CODE_SIGN_ENTITLEMENTS = "MHacksWatch Extension/MHacksWatch Extension.entitlements"; - CURRENT_PROJECT_VERSION = 18; + CURRENT_PROJECT_VERSION = 21; DEVELOPMENT_TEAM = 478C74MJ7T; INFOPLIST_FILE = "MHacksWatch Extension/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 12.2; + MARKETING_VERSION = 12.4.1; PRODUCT_BUNDLE_IDENTIFIER = com.MPowered.MHacks.watchkitapp.watchkitextension; PRODUCT_NAME = "${TARGET_NAME}"; SDKROOT = watchos; @@ -989,11 +989,11 @@ CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_SUSPICIOUS_MOVES = YES; CODE_SIGN_ENTITLEMENTS = "MHacksWatch Extension/MHacksWatch Extension.entitlements"; - CURRENT_PROJECT_VERSION = 18; + CURRENT_PROJECT_VERSION = 21; DEVELOPMENT_TEAM = 478C74MJ7T; INFOPLIST_FILE = "MHacksWatch Extension/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 12.2; + MARKETING_VERSION = 12.4.1; PRODUCT_BUNDLE_IDENTIFIER = com.MPowered.MHacks.watchkitapp.watchkitextension; PRODUCT_NAME = "${TARGET_NAME}"; SDKROOT = watchos; @@ -1122,7 +1122,7 @@ CODE_SIGN_ENTITLEMENTS = MHacks/MHacks.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 18; + CURRENT_PROJECT_VERSION = 21; DEVELOPMENT_TEAM = 478C74MJ7T; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -1131,7 +1131,7 @@ INFOPLIST_FILE = MHacks/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 12.2; + MARKETING_VERSION = 12.4.1; OTHER_SWIFT_FLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = com.MPowered.MHacks; PRODUCT_MODULE_NAME = "$(PRODUCT_NAME:c99extidentifier)"; @@ -1154,7 +1154,7 @@ CODE_SIGN_ENTITLEMENTS = MHacks/MHacks.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 18; + CURRENT_PROJECT_VERSION = 21; DEVELOPMENT_TEAM = 478C74MJ7T; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -1163,7 +1163,7 @@ INFOPLIST_FILE = MHacks/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 12.2; + MARKETING_VERSION = 12.4.1; OTHER_SWIFT_FLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = com.MPowered.MHacks; PRODUCT_MODULE_NAME = "$(PRODUCT_NAME:c99extidentifier)"; diff --git a/MHacks/Info.plist b/MHacks/Info.plist index ce73088..1ffd455 100644 --- a/MHacks/Info.plist +++ b/MHacks/Info.plist @@ -43,6 +43,8 @@ This application needs to access bluetooth for the purposes of scanning QR codes. NSCameraUsageDescription Privileged users can use the camera to scan tickets. + NSLocationAlwaysUsageDescription + Your location will be shown on the map. NSLocationWhenInUseUsageDescription Your location will be shown on the map. UIAppFonts diff --git a/MHacks/SiMHacksInfoController.swift b/MHacks/SiMHacksInfoController.swift index 769f7cc..639e971 100644 --- a/MHacks/SiMHacksInfoController.swift +++ b/MHacks/SiMHacksInfoController.swift @@ -22,7 +22,7 @@ class SiMHacksInfoController: UIViewController { let info = UITextView() info.textColor = UIColor.white info.backgroundColor = MHacksColor.backgroundDarkBlue - info.text = "SiMHacks = Sims + MHacks. A brand new way for hackers to interact and engage with each other!\n\n You will be given 5 quests at a time and once you complete a quest, you will be given a randomly generated new one.\n\n To complete a quest, you will need to find a fellow hacker who fulfills the description of the quest and scan their QR code. You also cannot scan the same hacker twice.\n\n You will have the option to refresh all quests every 3 hours in case you get stuck. \n\n Best of luck on your journey and most of all, have fun!" + info.text = "SiMHacks = Sims + MHacks. A brand new way for hackers to interact and engage with each other! The hacker with the top score at the end will receive a prize that will surely make them get their game on ;)\n\n You will be given 3 quests at a time and once you complete a quest, you will be given a randomly generated new one.\n\n To complete a quest, you will need to find a fellow hacker who's corresponding SiMHacks response fulfills the description of the quest and scan their QR code, located on their ticket. You also cannot scan the same hacker twice.\n\n Best of luck on your journey and most of all, have fun!" info.translatesAutoresizingMaskIntoConstraints = false info.textAlignment = .center info.font = UIFont(name: "AndaleMono", size: 25) diff --git a/MHacks/SiMHacksViewController.swift b/MHacks/SiMHacksViewController.swift index 6485337..827d170 100644 --- a/MHacks/SiMHacksViewController.swift +++ b/MHacks/SiMHacksViewController.swift @@ -28,7 +28,7 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U private var peopleOnBoard: [LeaderboardPosition] = [] - private let refreshControl = UIRefreshControl() + private let leaderboardRefreshControl = UIRefreshControl() private var selectedQuest: String = "" @@ -47,7 +47,7 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U private let leaderboardUser: UILabel = { let rankscore = UILabel() - rankscore.text = "Your rank: 0 | Your points: 0" + rankscore.text = "Your points: 0" rankscore.textColor = UIColor.white rankscore.numberOfLines = 0 rankscore.translatesAutoresizingMaskIntoConstraints = false @@ -148,7 +148,9 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) let alertAction = UIAlertAction(title: "OK", style: .default, handler: nil) alert.addAction(alertAction) - self.present(alert, animated: true, completion: nil) + DispatchQueue.main.async { + self.present(alert, animated: true, completion: nil) + } } func setupCollectionview() { @@ -165,22 +167,22 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U // Add Refresh Control to Table View if #available(iOS 10.0, *) { - leaderboard.refreshControl = refreshControl + leaderboard.refreshControl = leaderboardRefreshControl } else { - leaderboard.addSubview(refreshControl) + leaderboard.addSubview(leaderboardRefreshControl) } // Configure Refresh Control - refreshControl.addTarget(self, action: #selector(refreshLeaderboard(_:)), for: .valueChanged) - refreshControl.attributedTitle = NSAttributedString(string: "Updating leaderboard ...", attributes: [NSAttributedString.Key.font : UIFont(name: "AndaleMono", size: 12)!, NSAttributedString.Key.foregroundColor : MHacksColor.backgroundDarkBlue]) - refreshControl.tintColor = MHacksColor.backgroundDarkBlue + leaderboardRefreshControl.addTarget(self, action: #selector(refreshLeaderboard(_:)), for: .valueChanged) + leaderboardRefreshControl.attributedTitle = NSAttributedString(string: "Updating leaderboard ...", attributes: [NSAttributedString.Key.font : UIFont(name: "AndaleMono", size: 12)!, NSAttributedString.Key.foregroundColor : MHacksColor.backgroundDarkBlue]) + leaderboardRefreshControl.tintColor = MHacksColor.backgroundDarkBlue } @objc func refreshLeaderboard(_ sender: Any) { leaderboard.reloadData() getLeaderboard() getUserRankScore() - self.refreshControl.endRefreshing() + self.leaderboardRefreshControl.endRefreshing() } func getUserRankScore() { @@ -200,7 +202,7 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U // Refresh the UILabel to display the user's rank and score DispatchQueue.main.async { - self.leaderboardUser.text = "Your rank: 0 | Your points: " + String(user_points) + self.leaderboardUser.text = "Your points: " + String(user_points) } } } @@ -208,8 +210,12 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U func getLeaderboard() { APIManager.shared.getLeaderboard { newLeaderBoard in // TODO: find out the json keys for leaderboard + guard let leaderboardAndResponse = newLeaderBoard else { + self.makeAlertController(title: "ERROR: could not find game state.", message: "You must complete the SiMHacks questionnaire in order to play the game.") + return + } - guard let leaderboard = newLeaderBoard?["leaderboard"] as? NSArray else { + guard let leaderboard = leaderboardAndResponse["leaderboard"] as? NSArray else { self.makeAlertController(title: "ERROR: could not parse leaderboard.", message: "Could not parse leaderboard from state.") return } @@ -223,8 +229,8 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U let entry_points = e["points"] as! Int let entry_user = e["user"] as! [String: Any] let entry_user_name = entry_user["full_name"] as! String - print(entry_points) - print(entry_user_name) +// print(entry_points) +// print(entry_user_name) let entry_rank = rank new_board.append(LeaderboardPosition(position: entry_rank, name: entry_user_name, score: entry_points)) @@ -232,7 +238,7 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U } self.peopleOnBoard = new_board - print(self.peopleOnBoard) +// print(self.peopleOnBoard) // Refresh the leaderboard DispatchQueue.main.async { self.leaderboard.reloadData() @@ -257,7 +263,12 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U // Get data from API APIManager.shared.getGameState { newState in - guard let gState = newState?["state"] else { + guard let stateAndResponse = newState else { + self.makeAlertController(title: "ERROR: could not find game state.", message: "You must complete the SiMHacks questionnaire in order to play the game.") + return + } + + guard let gState = stateAndResponse["state"] else { self.makeAlertController(title: "ERROR: could not parse state.", message: "Could not parse state from the server response.") return } @@ -269,6 +280,8 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U return } + var newQuests: [Quest] = [] + for quest in quests { guard let q = quest as? [String: Any] else { self.makeAlertController(title: "ERROR: could not parse individual quest into dictionary.", message: "Could not convert quest into dictionary.") @@ -282,11 +295,13 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U // Find and replace the {} with the real question content fullQuestion = fullQuestion.replacingOccurrences(of: "{}", with: answer) - self.currentQuests.append(Quest(title: fullQuestion, points: numPoints)) + newQuests.append(Quest(title: fullQuestion, points: numPoints)) self.questNames.append(questionKeyword) } + self.currentQuests = newQuests + // Refresh the collectionview to display the quests DispatchQueue.main.async { self.collectionView.reloadData() @@ -372,9 +387,6 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U scannerNavigationController.isToolbarHidden = false present(scannerNavigationController, animated: true, completion: nil) - - self.getQuests() - self.getLeaderboard() } } @@ -382,6 +394,9 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U func scannerViewControllerDidFinish(scannerViewController: ScannerViewController) { dismiss(animated: true, completion: nil) + self.getUserRankScore() + self.getLeaderboard() + self.getQuests() } // MARK: CollectionView @@ -482,7 +497,7 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U self.selectedQuest = "" } else { collectionView.selectItem(at: indexPath, animated: true, scrollPosition: []) - self.selectedQuest = questNames[indexPath.row] + self.selectedQuest = self.questNames[indexPath.row] } return false @@ -500,6 +515,7 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U cell.positionLabel.text = "\(data.position)" cell.nameLabel.text = data.name cell.scoreLabel.text = "\(data.score)" + cell.selectionStyle = .none return cell } diff --git a/MHacks/UserViewController.swift b/MHacks/UserViewController.swift index 02987f7..eb3ecc9 100644 --- a/MHacks/UserViewController.swift +++ b/MHacks/UserViewController.swift @@ -285,7 +285,10 @@ final class UserViewController: UIViewController, LoginViewControllerDelegate, P let passesViewController = PKAddPassesViewController(pass: pass) passesViewController!.delegate = self - self.present(passesViewController!, animated: true, completion: nil) + + DispatchQueue.main.async { + self.present(passesViewController!, animated: true, completion: nil) + } } }