From 3d26a792af463c6716549a2f307ab689149a7ab4 Mon Sep 17 00:00:00 2001 From: Tamara Erlij Date: Thu, 13 Jun 2019 17:45:38 -0300 Subject: [PATCH] bronze --- .DS_Store | Bin 0 -> 6148 bytes LICENSE | 0 .../project.pbxproj | 8 ++ .../contents.xcworkspacedata | 0 .../xcshareddata/IDEWorkspaceChecks.plist | 0 LocalNotificationBase/AppDelegate.swift | 1 + .../AppIcon.appiconset/Contents.json | 0 .../Assets.xcassets/Contents.json | 0 .../Base.lproj/LaunchScreen.storyboard | 0 .../Base.lproj/Main.storyboard | 121 +++++++++++++++++- .../BaseViewController.swift | 26 +--- .../BronzeViewController.swift | 60 +++++++++ LocalNotificationBase/Info.plist | 0 LocalNotificationBase/PickerView.swift | 9 ++ LocalNotificationBase/enviarNotificacao.swift | 39 ++++++ README.md | 0 16 files changed, 239 insertions(+), 25 deletions(-) create mode 100644 .DS_Store mode change 100644 => 100755 LICENSE mode change 100644 => 100755 LocalNotificationBase.xcodeproj/project.pbxproj mode change 100644 => 100755 LocalNotificationBase.xcodeproj/project.xcworkspace/contents.xcworkspacedata mode change 100644 => 100755 LocalNotificationBase.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist mode change 100644 => 100755 LocalNotificationBase/AppDelegate.swift mode change 100644 => 100755 LocalNotificationBase/Assets.xcassets/AppIcon.appiconset/Contents.json mode change 100644 => 100755 LocalNotificationBase/Assets.xcassets/Contents.json mode change 100644 => 100755 LocalNotificationBase/Base.lproj/LaunchScreen.storyboard mode change 100644 => 100755 LocalNotificationBase/Base.lproj/Main.storyboard mode change 100644 => 100755 LocalNotificationBase/BaseViewController.swift create mode 100644 LocalNotificationBase/BronzeViewController.swift mode change 100644 => 100755 LocalNotificationBase/Info.plist create mode 100644 LocalNotificationBase/PickerView.swift create mode 100644 LocalNotificationBase/enviarNotificacao.swift mode change 100644 => 100755 README.md diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 - + @@ -31,9 +31,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LocalNotificationBase/BaseViewController.swift b/LocalNotificationBase/BaseViewController.swift old mode 100644 new mode 100755 index b3615fb..671ce43 --- a/LocalNotificationBase/BaseViewController.swift +++ b/LocalNotificationBase/BaseViewController.swift @@ -17,30 +17,8 @@ class BaseViewController: UIViewController { } @IBAction func remindButton(_ sender: Any) { - let notificationCenter = UNUserNotificationCenter.current() - notificationCenter.getNotificationSettings { (settings) in - if settings.authorizationStatus == .authorized { - - let content = UNMutableNotificationContent() - content.title = NSString.localizedUserNotificationString(forKey: "Lembre-se", arguments: nil) - content.body = NSString.localizedUserNotificationString(forKey: "Você se lembrou", arguments: nil) - content.sound = UNNotificationSound.default - - let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false) - - 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") - } - } + + enviarNotificacao(titulo: "Lembre-se 2", corpo: "Corpo", identificador: "1", intervalo: "5", badge: true, som: true) } } diff --git a/LocalNotificationBase/BronzeViewController.swift b/LocalNotificationBase/BronzeViewController.swift new file mode 100644 index 0000000..5376b1c --- /dev/null +++ b/LocalNotificationBase/BronzeViewController.swift @@ -0,0 +1,60 @@ +// +// TableViewController.swift +// LocalNotificationBase +// +// Created by Tamara Erlij on 13/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import UIKit + +class BronzeViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource { + + + + + @IBOutlet weak var titulo: UITextField! + @IBOutlet weak var corpo: UITextField! + @IBOutlet weak var picker: UIPickerView! + @IBOutlet weak var som: UISwitch! + @IBOutlet weak var badge: UISwitch! + + let array = ["1","2","3","4","5","6","7","8","9","10"] + var pickerSelected = "" + + @IBAction func enviar(_ sender: Any) { + + let titulo = self.titulo.text as! String + let corpo = self.corpo.text as! String + let som = self.som.isOn + let badge = self.badge.isOn + + enviarNotificacao(titulo: titulo, corpo: corpo, identificador: "1", intervalo: pickerSelected, badge: badge, som: som) +// print(titulo, corpo, som, badge, pickerSelected) + } + override func viewDidLoad() { + + super.viewDidLoad() + + picker.dataSource = self + picker.delegate = self + } + + + func numberOfComponents(in pickerView: UIPickerView) -> Int { + return 1 + } + + func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { + return array.count + } + + func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { + return array[row] + } + func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { + pickerSelected = array[row] + } + + +} diff --git a/LocalNotificationBase/Info.plist b/LocalNotificationBase/Info.plist old mode 100644 new mode 100755 diff --git a/LocalNotificationBase/PickerView.swift b/LocalNotificationBase/PickerView.swift new file mode 100644 index 0000000..c109962 --- /dev/null +++ b/LocalNotificationBase/PickerView.swift @@ -0,0 +1,9 @@ +// +// PickerView.swift +// LocalNotificationBase +// +// Created by Tamara Erlij on 13/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import Foundation diff --git a/LocalNotificationBase/enviarNotificacao.swift b/LocalNotificationBase/enviarNotificacao.swift new file mode 100644 index 0000000..a011c40 --- /dev/null +++ b/LocalNotificationBase/enviarNotificacao.swift @@ -0,0 +1,39 @@ +// +// enviarNotificacao.swift +// LocalNotificationBase +// +// Created by Tamara Erlij on 13/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import Foundation +import UserNotifications +func enviarNotificacao(titulo:String, corpo:String, identificador:String, intervalo:String , badge:Bool, som:Bool) { + let notificationCenter = UNUserNotificationCenter.current() + notificationCenter.getNotificationSettings { (settings) in + if settings.authorizationStatus == .authorized { + + let content = UNMutableNotificationContent() + content.title = NSString.localizedUserNotificationString(forKey: titulo, arguments: nil) + content.body = NSString.localizedUserNotificationString(forKey: corpo, arguments: nil) + content.sound = som ? UNNotificationSound.default : nil + content.badge = badge ? 1 : 0 + + guard let tempo = TimeInterval(intervalo) else { return } + + let trigger = UNTimeIntervalNotificationTrigger(timeInterval: tempo, repeats: false) + + let request = UNNotificationRequest(identifier: identificador, 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") + } + } +} diff --git a/README.md b/README.md old mode 100644 new mode 100755