From aa419df75c3537090f307ffabeff45c39799697a Mon Sep 17 00:00:00 2001 From: Mariana Lima Date: Thu, 13 Jun 2019 18:24:34 -0300 Subject: [PATCH] mariana lima bronze --- .DS_Store | Bin 0 -> 6148 bytes .../project.pbxproj | 4 + LocalNotificationBase/AppDelegate.swift | 2 +- .../Base.lproj/Main.storyboard | 184 ++++++++++++++++++ .../CollectionViewCell.swift | 14 ++ .../TableViewController.swift | 89 +++++++++ 6 files changed, 292 insertions(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 LocalNotificationBase/CollectionViewCell.swift create mode 100644 LocalNotificationBase/TableViewController.swift diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b8866fe029de0f47f7055610fcfaee668c855bb4 GIT binary patch literal 6148 zcmeHKOHKnZ41IwvDzWL39XSC~ZxD^ju42;*fLcC9Ei-~5vCKs{0hi(^JbyqPF*^`K z$d=;gIJT2KX_5(m)I6=Gzy!dUO)!ZuAmSbzI`Ck@q%}4;M~fZSxE?6<7hSUU6U@2l zB`&eQ{rTaP$#ZIK?ylEmpKUJkYw^+)NkCcH7zZUS7XnvAf-`_-2Je2Lr)C zFc1s`13$w6?`)CrkzwdyAQ%V+J{genA+re<$7-lY2bDenh$FgHXv5{=UN8_0{4)m9XttO&+?3y~U$!TAZDzY*6Op(o28DL-Cx9I}M~-#S# + @@ -34,6 +42,182 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LocalNotificationBase/CollectionViewCell.swift b/LocalNotificationBase/CollectionViewCell.swift new file mode 100644 index 0000000..3ef035d --- /dev/null +++ b/LocalNotificationBase/CollectionViewCell.swift @@ -0,0 +1,14 @@ +// +// CollectionViewCell.swift +// LocalNotificationBase +// +// Created by Mariana Lima on 13/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import UIKit +import UserNotifications + +class CollectionViewCell: UICollectionViewCell { + +} diff --git a/LocalNotificationBase/TableViewController.swift b/LocalNotificationBase/TableViewController.swift new file mode 100644 index 0000000..30a4ed9 --- /dev/null +++ b/LocalNotificationBase/TableViewController.swift @@ -0,0 +1,89 @@ +// +// TableViewController.swift +// LocalNotificationBase +// +// Created by Mariana Lima on 13/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import UIKit +import UserNotifications + +class TableViewController: UITableViewController, UIPickerViewDelegate, UIPickerViewDataSource { + func numberOfComponents(in pickerView: UIPickerView) -> Int { + return 1 + } + + func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { + return conteudopicker.count + } + func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { + return conteudopicker [row] + } + + + @IBOutlet weak var titulobase: UITextField! + @IBOutlet weak var corpobase: UITextField! + @IBOutlet weak var segmentedControl: UISwitch! + @IBOutlet weak var segmentedControlNot: UISwitch! + @IBAction func enviar(_ sender: Any) { + + let content = UNMutableNotificationContent() + if segmentedControl.isOn { + + content.sound = UNNotificationSound.default + } + else { + + content.sound = nil + } + if segmentedControlNot.isOn{ + content.badge = true + } + else { + content.badge = false + } + + if let texto = self.titulobase.text { + content.title = NSString.localizedUserNotificationString(forKey: texto, arguments: nil) + } + + if let corpo = self.corpobase.text { + content.body = NSString.localizedUserNotificationString(forKey: corpo, arguments: nil) + } + + let trigger = UNTimeIntervalNotificationTrigger(timeInterval: TimeInterval(self.picker.selectedRow(inComponent: 0)), repeats: false) + + let notificationCenter = UNUserNotificationCenter.current() + notificationCenter.getNotificationSettings { (settings) in + if settings.authorizationStatus == .authorized { + + + let request = UNNotificationRequest(identifier: "5seconds", content: content, trigger: trigger) + + let center = UNUserNotificationCenter.current() + center.add(request) { (error : Error?) in + if let error = error { + print(error.localizedDescription) + } + } + + } else { + print("Impossível mandar notificação - permissão negada") + } + } + + + + } + + @IBOutlet weak var picker: UIPickerView! + var conteudopicker : [String] = [String] () + + override func viewDidLoad() { + super.viewDidLoad() + conteudopicker = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"] + picker.delegate = self + picker.dataSource = self + } +}