diff --git a/ProjectClock.xcodeproj/project.pbxproj b/ProjectClock.xcodeproj/project.pbxproj index 03a8f43..bcbddf0 100644 --- a/ProjectClock.xcodeproj/project.pbxproj +++ b/ProjectClock.xcodeproj/project.pbxproj @@ -18,6 +18,8 @@ 4FF0684825A5F18800304E6B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4FF0684725A5F18800304E6B /* Assets.xcassets */; }; 4FF0684B25A5F18800304E6B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4FF0684925A5F18800304E6B /* LaunchScreen.storyboard */; }; 7C83963625AF375B0027A94C /* NotificationLogic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83963525AF375B0027A94C /* NotificationLogic.swift */; }; + 7C83963925AF68980027A94C /* TestingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83963825AF68980027A94C /* TestingViewController.swift */; }; + 7C83963C25AF6B6B0027A94C /* Alarm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83963B25AF6B6B0027A94C /* Alarm.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -36,6 +38,8 @@ 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 = ""; }; + 7C83963B25AF6B6B0027A94C /* Alarm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alarm.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -82,6 +86,8 @@ 7C83963525AF375B0027A94C /* NotificationLogic.swift */, 4F98955125A9260400F51321 /* Net.swift */, 4F509BD125AE22D100726227 /* Models.swift */, + 7C83963825AF68980027A94C /* TestingViewController.swift */, + 7C83963B25AF6B6B0027A94C /* Alarm.swift */, ); path = ProjectClock; sourceTree = ""; @@ -167,9 +173,11 @@ 4F8A607125A9160400D88DC3 /* AddAlarmViewController.swift in Sources */, 4F98955225A9260400F51321 /* Net.swift in Sources */, 4F8A607525A919E600D88DC3 /* Logic.swift in Sources */, + 7C83963925AF68980027A94C /* TestingViewController.swift in Sources */, 4FF0684325A5F18700304E6B /* ViewController.swift in Sources */, 4FF0683F25A5F18700304E6B /* AppDelegate.swift in Sources */, 4FF0684125A5F18700304E6B /* SceneDelegate.swift in Sources */, + 7C83963C25AF6B6B0027A94C /* Alarm.swift in Sources */, 4F509BD225AE22D100726227 /* Models.swift in Sources */, 7C83963625AF375B0027A94C /* NotificationLogic.swift in Sources */, ); diff --git a/ProjectClock/Base.lproj/Main.storyboard b/ProjectClock/Base.lproj/Main.storyboard index a6eb690..02f1288 100644 --- a/ProjectClock/Base.lproj/Main.storyboard +++ b/ProjectClock/Base.lproj/Main.storyboard @@ -211,6 +211,42 @@ + + + + + + + + + + + + + + + + + + + + @@ -296,7 +332,7 @@ - + @@ -502,6 +538,7 @@ + diff --git a/ProjectClock/NotificationLogic.swift b/ProjectClock/NotificationLogic.swift index e491d08..44c3392 100644 --- a/ProjectClock/NotificationLogic.swift +++ b/ProjectClock/NotificationLogic.swift @@ -7,14 +7,15 @@ import Foundation import CoreMotion +import UserNotifications let motionManager = CMMotionManager() func getAccelerometer() { motionManager.startAccelerometerUpdates() - + //print(motionManager.accelerometerData) if let accelerometerData = motionManager.accelerometerData { - print(accelerometerData) + print("Acclerometer: \(accelerometerData)") } } diff --git a/ProjectClock/TestingViewController.swift b/ProjectClock/TestingViewController.swift new file mode 100644 index 0000000..634e77f --- /dev/null +++ b/ProjectClock/TestingViewController.swift @@ -0,0 +1,75 @@ +// +// TestingViewController.swift +// ProjectClock +// +// Created by Aaron Saporito on 1/13/21. +// + +import UIKit +import UserNotifications + +class TestingViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + UNUserNotificationCenter.current().requestAuthorization(options: [.alert]) { + (granted, error) in + if granted { + print("Authorized Notifications") + } else { + print("Error: No notification access") + } + } + + // Do any additional setup after loading the view. + } + + @IBAction func getAccel(_ sender: Any) { + getAccelerometer() + } + + //Sends a test notification + @IBAction func sendNotification(_ sender: Any) { + var alarm = Alarm(alarmTime: Date(), text: "Hello there!", wakeMethod: WVM(name: "walking", desc: "Walk")) + + let content = UNMutableNotificationContent() + + //Date formatting to string + let today = Date() + let formatter1 = DateFormatter() + formatter1.dateStyle = .short + print(formatter1.string(from: today)) + + //Notification content + content.title = alarm.text + content.subtitle = formatter1.string(from: today) + content.body = "Wake method: \(alarm.wakeMethod)" + + // 2 + let imageName = "applelogo" + 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] + + // 3 + let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0, repeats: false) + let request = UNNotificationRequest(identifier: "notification.id.01", content: content, trigger: trigger) + + // 4 + UNUserNotificationCenter.current().add(request, withCompletionHandler: nil) + } + + /* + // MARK: - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + // Get the new view controller using segue.destination. + // Pass the selected object to the new view controller. + } + */ + +}