Merge branch 'main' of github.com:hykilpikonna/ProjectClock into main
This commit is contained in:
@@ -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 = "<group>"; };
|
||||
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 = "<group>"; };
|
||||
7C83963825AF68980027A94C /* TestingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestingViewController.swift; sourceTree = "<group>"; };
|
||||
7C83963B25AF6B6B0027A94C /* Alarm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alarm.swift; sourceTree = "<group>"; };
|
||||
/* 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 = "<group>";
|
||||
@@ -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 */,
|
||||
);
|
||||
|
||||
@@ -211,6 +211,42 @@
|
||||
</objects>
|
||||
<point key="canvasLocation" x="140.57971014492756" y="815.625"/>
|
||||
</scene>
|
||||
<!--Item-->
|
||||
<scene sceneID="x23-kV-b5u">
|
||||
<objects>
|
||||
<viewController id="r8W-6e-Hn2" customClass="TestingViewController" 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"/>
|
||||
<subviews>
|
||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="GhB-GA-PWg">
|
||||
<rect key="frame" x="93" y="128" width="229" height="40"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="23"/>
|
||||
<state key="normal" title="Send Accel. to Console"/>
|
||||
<connections>
|
||||
<action selector="getAccel:" destination="r8W-6e-Hn2" eventType="touchUpInside" id="hDu-Hj-vnU"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="8o4-jF-mCC">
|
||||
<rect key="frame" x="154" y="232" width="110" height="41"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="24"/>
|
||||
<state key="normal" title="Send Notif"/>
|
||||
<connections>
|
||||
<action selector="sendNotification:" destination="r8W-6e-Hn2" eventType="touchUpInside" id="ry0-VK-YRb"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<viewLayoutGuide key="safeArea" id="hX1-uy-i87"/>
|
||||
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
|
||||
</view>
|
||||
<tabBarItem key="tabBarItem" title="Item" id="QZ2-fJ-hLg"/>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="mZu-oh-Lmb" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="-529" y="177"/>
|
||||
</scene>
|
||||
<!--Alarm-->
|
||||
<scene sceneID="Dgv-Jj-q5Y">
|
||||
<objects>
|
||||
@@ -296,7 +332,7 @@
|
||||
</tableViewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="lGJ-Tm-q0E" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="-597.10144927536237" y="815.625"/>
|
||||
<point key="canvasLocation" x="-493" y="869"/>
|
||||
</scene>
|
||||
<!--Add Alarm View Controller-->
|
||||
<scene sceneID="sJi-AZ-FUw">
|
||||
@@ -502,6 +538,7 @@
|
||||
<connections>
|
||||
<segue destination="TfJ-ri-6I1" kind="relationship" relationship="viewControllers" destinationCreationSelector="Alarm" id="gxt-tS-tDQ"/>
|
||||
<segue destination="BYZ-38-t0r" kind="relationship" relationship="viewControllers" destinationCreationSelector="Account" id="NN6-JO-Hmi"/>
|
||||
<segue destination="r8W-6e-Hn2" kind="relationship" relationship="viewControllers" destinationCreationSelector="Testing" id="SLn-vq-UnH"/>
|
||||
</connections>
|
||||
</tabBarController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="S6R-Xr-Nfe" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
|
||||
|
||||
+10
-1
@@ -9,6 +9,7 @@ import Foundation
|
||||
/// Base URL of the HTTP server
|
||||
let baseUrl = "http://localhost:8080/api" // TODO: Production settings
|
||||
let JSON = JSONDecoder()
|
||||
let localStorage = UserDefaults(suiteName: "group.org.hydev.alarm.clock")!
|
||||
|
||||
/// API class
|
||||
struct API<T>
|
||||
@@ -65,7 +66,7 @@ func createUrl(_ node: String, _ params: [String: String]? = [:]) -> URL
|
||||
}
|
||||
|
||||
/**
|
||||
Send a HTTP request
|
||||
Send a HTTP request. Email and authentication token (the initial hash of a password) is automatically added if they exist in localStorage.
|
||||
|
||||
- Parameter api: API Node (Eg. APIs.register)
|
||||
- Parameter params: Parameters to send to the server (Check the documentation of the API node to see which parameters you need)
|
||||
@@ -74,6 +75,14 @@ func createUrl(_ node: String, _ params: [String: String]? = [:]) -> URL
|
||||
*/
|
||||
func send<T: Decodable>(_ api: API<T>, _ params: [String: String]? = [:], _ success: @escaping (T) -> Void, err: @escaping (String) -> Void = {it in})
|
||||
{
|
||||
// Add default params
|
||||
var params = params
|
||||
if params != nil
|
||||
{
|
||||
if params!["email"] == nil { params!["email"] = localStorage.string(forKey: "email") }
|
||||
if params!["pass"] == nil { params!["pass"] = localStorage.string(forKey: "pass") }
|
||||
}
|
||||
|
||||
let url = createUrl(api.loc, params)
|
||||
|
||||
// Create task
|
||||
|
||||
@@ -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)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.developer.healthkit</key>
|
||||
<true/>
|
||||
<key>com.apple.developer.healthkit.access</key>
|
||||
<array/>
|
||||
<key>com.apple.security.application-groups</key>
|
||||
<array>
|
||||
<string>group.org.hydev.alarm.clock</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user