Merge branch 'main' of github.com:hykilpikonna/ProjectClock into main
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "applelogo.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
@@ -31,34 +31,32 @@ class TestingViewController: UIViewController {
|
||||
|
||||
//Sends a test notification
|
||||
@IBAction func sendNotification(_ sender: Any) {
|
||||
var alarm = Alarm(alarmTime: Date(), text: "Hello there!", wakeMethod: WVM(name: "walking", desc: "Walk"))
|
||||
let alarm = Alarm(alarmTime: Date(), text: "Good morning!", 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))
|
||||
formatter1.dateStyle = .long
|
||||
|
||||
//Notification content
|
||||
content.title = alarm.text
|
||||
content.subtitle = formatter1.string(from: today)
|
||||
content.body = "Wake method: \(alarm.wakeMethod)"
|
||||
content.body = "Wake method: \(alarm.wakeMethod.name)"
|
||||
|
||||
// 2
|
||||
let imageName = "applelogo"
|
||||
// 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]
|
||||
|
||||
// 3
|
||||
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0, repeats: false)
|
||||
|
||||
// Readies notification to be sent
|
||||
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
|
||||
let request = UNNotificationRequest(identifier: "notification.id.01", content: content, trigger: trigger)
|
||||
|
||||
// 4
|
||||
// Sends notification
|
||||
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,46 @@ import UIKit
|
||||
|
||||
class ViewController: UIViewController {
|
||||
|
||||
@IBOutlet var table: UITableView!
|
||||
|
||||
var models = [MyAlarm]()
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
// Do any additional setup after loading the view.
|
||||
table.delegate = self
|
||||
table.dataSource = self
|
||||
}
|
||||
}
|
||||
|
||||
extension ViewController: UITableViewDelegate {
|
||||
|
||||
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
tableView.deselectRow(at: indexPath, animated: true)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension ViewController: UITableViewDataSource {
|
||||
|
||||
func numberOfSections(in tableView: UITableView) -> Int {
|
||||
return 1
|
||||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return models.count
|
||||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
|
||||
cell.textLabel?.text = models[indexPath.row].title
|
||||
|
||||
return cell
|
||||
}
|
||||
}
|
||||
|
||||
struct MyAlarm {
|
||||
let title: String
|
||||
let date: Date
|
||||
let identifier: String
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Reference in New Issue
Block a user