From acfbf6e0dae6d5364db88d8635c3a4e49475f01c Mon Sep 17 00:00:00 2001 From: Aaron Date: Sun, 24 Jan 2021 17:28:55 -0500 Subject: [PATCH] Renamed TestingViewController to DebugViewController --- ProjectClock.xcodeproj/project.pbxproj | 12 ++++--- ProjectClock/Base.lproj/Main.storyboard | 2 +- ProjectClock/DebugViewController.swift | 43 ++++++++++++++++++++++++ ProjectClock/TestingViewController.swift | 29 ++-------------- 4 files changed, 54 insertions(+), 32 deletions(-) create mode 100644 ProjectClock/DebugViewController.swift diff --git a/ProjectClock.xcodeproj/project.pbxproj b/ProjectClock.xcodeproj/project.pbxproj index 5bf773f..4dd0dd6 100644 --- a/ProjectClock.xcodeproj/project.pbxproj +++ b/ProjectClock.xcodeproj/project.pbxproj @@ -19,9 +19,10 @@ 4FF0684625A5F18700304E6B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4FF0684425A5F18700304E6B /* Main.storyboard */; }; 4FF0684825A5F18800304E6B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4FF0684725A5F18800304E6B /* Assets.xcassets */; }; 4FF0684B25A5F18800304E6B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4FF0684925A5F18800304E6B /* LaunchScreen.storyboard */; }; + 7C12BC7825BE25C000E5659C /* Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C12BC7725BE25C000E5659C /* Notification.swift */; }; 7C5DAE9C25AF812200E44C52 /* clock.png in Resources */ = {isa = PBXBuildFile; fileRef = 7C5DAE9B25AF812200E44C52 /* clock.png */; }; 7C83963625AF375B0027A94C /* NotificationLogic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83963525AF375B0027A94C /* NotificationLogic.swift */; }; - 7C83963925AF68980027A94C /* TestingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83963825AF68980027A94C /* TestingViewController.swift */; }; + 7C83963925AF68980027A94C /* DebugViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83963825AF68980027A94C /* DebugViewController.swift */; }; C7E638E825B88F8B00799512 /* MathExpressions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7E638E725B88F8B00799512 /* MathExpressions.swift */; }; F0DF7C0725BCD9FC0064A26B /* StopwatchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0DF7C0625BCD9FC0064A26B /* StopwatchViewController.swift */; }; /* End PBXBuildFile section */ @@ -41,11 +42,12 @@ 4FF0684725A5F18800304E6B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 4FF0684A25A5F18800304E6B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 4FF0684C25A5F18800304E6B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 7C12BC7725BE25C000E5659C /* Notification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = ""; }; 7C5DAE9B25AF812200E44C52 /* clock.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = clock.png; sourceTree = ""; }; 7C83962D25AF34F00027A94C /* ProjectClock.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = ProjectClock.entitlements; sourceTree = ""; }; 7C83962F25AF34F10027A94C /* HealthKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = HealthKit.framework; path = System/Library/Frameworks/HealthKit.framework; sourceTree = SDKROOT; }; 7C83963525AF375B0027A94C /* NotificationLogic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationLogic.swift; sourceTree = ""; }; - 7C83963825AF68980027A94C /* TestingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestingViewController.swift; sourceTree = ""; }; + 7C83963825AF68980027A94C /* DebugViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebugViewController.swift; sourceTree = ""; }; C7E638E725B88F8B00799512 /* MathExpressions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MathExpressions.swift; sourceTree = ""; }; F0DF7C0625BCD9FC0064A26B /* StopwatchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StopwatchViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -91,7 +93,8 @@ 4FA419AE25AF93EC004CE0FC /* AlarmViewController.swift */, 4F8A607025A9160400D88DC3 /* AddAlarmViewController.swift */, F0DF7C0625BCD9FC0064A26B /* StopwatchViewController.swift */, - 7C83963825AF68980027A94C /* TestingViewController.swift */, + 7C83963825AF68980027A94C /* DebugViewController.swift */, + 7C12BC7725BE25C000E5659C /* Notification.swift */, 4FD642DF25B4D5F30069171E /* AlarmActivationViewController.swift */, 4FD642D225B48C380069171E /* AlarmActivator.swift */, 4FF0684425A5F18700304E6B /* Main.storyboard */, @@ -188,7 +191,7 @@ files = ( 4F8A607125A9160400D88DC3 /* AddAlarmViewController.swift in Sources */, 4F98955225A9260400F51321 /* Net.swift in Sources */, - 7C83963925AF68980027A94C /* TestingViewController.swift in Sources */, + 7C83963925AF68980027A94C /* DebugViewController.swift in Sources */, 4FF0684325A5F18700304E6B /* AccountViewController.swift in Sources */, F0DF7C0725BCD9FC0064A26B /* StopwatchViewController.swift in Sources */, 4FF0683F25A5F18700304E6B /* AppDelegate.swift in Sources */, @@ -196,6 +199,7 @@ 4FD642DB25B4B7F60069171E /* Utils.swift in Sources */, 4FA419AF25AF93EC004CE0FC /* AlarmViewController.swift in Sources */, 4F509BD225AE22D100726227 /* Models.swift in Sources */, + 7C12BC7825BE25C000E5659C /* Notification.swift in Sources */, C7E638E825B88F8B00799512 /* MathExpressions.swift in Sources */, 7C83963625AF375B0027A94C /* NotificationLogic.swift in Sources */, 4FD642E025B4D5F30069171E /* AlarmActivationViewController.swift in Sources */, diff --git a/ProjectClock/Base.lproj/Main.storyboard b/ProjectClock/Base.lproj/Main.storyboard index 1403bf7..d3c9efa 100644 --- a/ProjectClock/Base.lproj/Main.storyboard +++ b/ProjectClock/Base.lproj/Main.storyboard @@ -204,7 +204,7 @@ - + diff --git a/ProjectClock/DebugViewController.swift b/ProjectClock/DebugViewController.swift new file mode 100644 index 0000000..a7c145a --- /dev/null +++ b/ProjectClock/DebugViewController.swift @@ -0,0 +1,43 @@ +// +// TestingViewController.swift +// ProjectClock +// +// Created by Aaron Saporito on 1/13/21. +// + +import UIKit +import UserNotifications + +class DebugViewController: UIViewController +{ + override func viewDidLoad() + { + super.viewDidLoad() + + // Request notification permission + UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { success, error in + if success { + print("All set!") + } else if let error = error { + print(error.localizedDescription) + } + } + } + + //Sends a test notification + @IBAction func sendNotification(_ sender: Any) + { + Notification(alarm: Alarms.fromLocal().listEnabled[0]).sendNotification() + } + + @IBAction func addAlarm(_ sender: Any) + { + let (h, m, _) = Date().getHMS() + Alarms.fromLocal().apply { $0.list.append(Alarm(hour: h, minute: m, text: "Test alarm - \(h * m)", wakeMethod: wvms[1], repeats: [true, true, true, true, true, true, true], lastActivate: Date().added(.minute, -1))) }.localSave() + } + + @IBAction func deleteAlarm(_ sender: Any) + { + Alarms.fromLocal().apply { $0.list.removeAll() }.localSave() + } +} diff --git a/ProjectClock/TestingViewController.swift b/ProjectClock/TestingViewController.swift index c2fbcf5..a7c145a 100644 --- a/ProjectClock/TestingViewController.swift +++ b/ProjectClock/TestingViewController.swift @@ -8,7 +8,7 @@ import UIKit import UserNotifications -class TestingViewController: UIViewController +class DebugViewController: UIViewController { override func viewDidLoad() { @@ -27,32 +27,7 @@ class TestingViewController: UIViewController //Sends a test notification @IBAction func sendNotification(_ sender: Any) { - let alarm = Alarm(hour: 7, minute: 20, text: "Good morning!", wakeMethod: WVM(name: "walking", desc: "Walk")) - - let content = UNMutableNotificationContent() - - //Date formatting to string - let today = Date() - let formatter1 = DateFormatter() - formatter1.dateStyle = .long - - //Notification content - content.title = alarm.text - content.subtitle = formatter1.string(from: today) - content.body = "Wake method: \(alarm.wakeMethod.name)" - - // Notification image content - let imageName = "clock" - guard let imageURL = Bundle.main.url(forResource: imageName, withExtension: "png") else { return } - let attachment = try! UNNotificationAttachment(identifier: imageName, url: imageURL, options: .none) - content.attachments = [attachment] - - // Readies notification to be sent - let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 10, repeats: false) - let request = UNNotificationRequest(identifier: "notification.id.01", content: content, trigger: trigger) - - // Sends notification - UNUserNotificationCenter.current().add(request, withCompletionHandler: nil) + Notification(alarm: Alarms.fromLocal().listEnabled[0]).sendNotification() } @IBAction func addAlarm(_ sender: Any)