From ac749302d091dffe72151747564bad25bcc445a2 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Monteiro de Carvalho Date: Thu, 13 Jun 2019 17:37:27 -0300 Subject: [PATCH] LuizNotificationBronze --- .DS_Store | Bin 0 -> 6148 bytes LICENSE | 0 .../project.pbxproj | 4 + .../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 | 119 ++++++++++++++- .../BaseViewController.swift | 1 + .../BronzeViewController.swift | 135 ++++++++++++++++++ LocalNotificationBase/Info.plist | 0 README.md | 0 14 files changed, 258 insertions(+), 2 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 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 - + @@ -10,7 +10,120 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -31,9 +144,11 @@ + + diff --git a/LocalNotificationBase/BaseViewController.swift b/LocalNotificationBase/BaseViewController.swift old mode 100644 new mode 100755 index b3615fb..f688e9d --- a/LocalNotificationBase/BaseViewController.swift +++ b/LocalNotificationBase/BaseViewController.swift @@ -26,6 +26,7 @@ class BaseViewController: UIViewController { 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) diff --git a/LocalNotificationBase/BronzeViewController.swift b/LocalNotificationBase/BronzeViewController.swift new file mode 100644 index 0000000..3a6cd92 --- /dev/null +++ b/LocalNotificationBase/BronzeViewController.swift @@ -0,0 +1,135 @@ +// +// BronzeViewController.swift +// LocalNotificationBase +// +// Created by Luiz Henrique Monteiro de Carvalho on 13/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import UIKit +import UserNotifications +class BronzeViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource { + + func numberOfComponents(in pickerView: UIPickerView) -> Int { + return 1 + } + + func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { + return pickerData.count + } + func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { + return pickerData[row] + } + + + + + @IBOutlet weak var tituloField: UITextField! + @IBOutlet weak var corpoField: UITextField! + + + @IBOutlet weak var pickerSegundos: UIPickerView! + var pickerData: [String] = [String]() + + @IBOutlet weak var somSwitchOutlet: UISwitch! + @IBOutlet weak var badgeSwitchOutlet: UISwitch! + + + + override func viewDidLoad() { + super.viewDidLoad() + + self.pickerSegundos.delegate = self + self.pickerSegundos.dataSource = self + + pickerData = ["0","1","2","3","4","5","6","7","8","9","10"] + + // Do any additional setup after loading the view. + } + + + + + @IBAction func enviarButton(_ sender: Any) { + + let notificationCenterBronze = UNUserNotificationCenter.current() + let contentBronze = UNMutableNotificationContent() + + if let tituloFieldText = self.tituloField.text{ + contentBronze.title = NSString.localizedUserNotificationString(forKey: tituloFieldText, arguments: nil) + } + + if let corpoFieldText = self.corpoField.text{ + contentBronze.body = NSString.localizedUserNotificationString(forKey: corpoFieldText, arguments: nil) + } + + + + if self.somSwitchOutlet.isOn{ + contentBronze.sound = UNNotificationSound.default + }else{ + contentBronze.sound = .none + } + + if self.badgeSwitchOutlet.isOn{ + contentBronze.badge = 1 + } + + + let triggerBronze = UNTimeIntervalNotificationTrigger(timeInterval: TimeInterval(self.pickerSegundos.selectedRow(inComponent: 0)), repeats: false) + + + let requestBronze = UNNotificationRequest(identifier: "XSegundos", content: contentBronze, trigger: triggerBronze) + + + notificationCenterBronze.getNotificationSettings { (settingsBronze) in + if settingsBronze.authorizationStatus == .authorized{ + + let centerBronze = UNUserNotificationCenter.current() + + centerBronze.add(requestBronze) {(error: Error?) in + if let error = error { + print(error.localizedDescription) + } + } + }else { + print("Deu não") + } + + + + + + + + + } + } + } + +// 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") +//} +// + + + /* + // 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. + } + */ + + diff --git a/LocalNotificationBase/Info.plist b/LocalNotificationBase/Info.plist old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755