Renamed TestingViewController to DebugViewController
This commit is contained in:
@@ -204,7 +204,7 @@
|
||||
<!--Debug-->
|
||||
<scene sceneID="x23-kV-b5u">
|
||||
<objects>
|
||||
<viewController id="r8W-6e-Hn2" customClass="TestingViewController" customModule="ProjectClock" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<viewController id="r8W-6e-Hn2" customClass="DebugViewController" customModule="ProjectClock" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<view key="view" contentMode="scaleToFill" id="xd9-wc-Vc7">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user