diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/.DS_Store differ diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/LocalNotificationBase.xcodeproj/project.pbxproj b/LocalNotificationBase.xcodeproj/project.pbxproj old mode 100644 new mode 100755 index dd7afac..8f6b039 --- a/LocalNotificationBase.xcodeproj/project.pbxproj +++ b/LocalNotificationBase.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 956323AC22B2D049001505FB /* BronzeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 956323AB22B2D049001505FB /* BronzeViewController.swift */; }; + 956323AE22B2E0BC001505FB /* enviarNotificacao.swift in Sources */ = {isa = PBXBuildFile; fileRef = 956323AD22B2E0BC001505FB /* enviarNotificacao.swift */; }; AA6671C922B1292D00824252 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA6671C822B1292D00824252 /* AppDelegate.swift */; }; AA6671CB22B1292D00824252 /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA6671CA22B1292D00824252 /* BaseViewController.swift */; }; AA6671CE22B1292D00824252 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = AA6671CC22B1292D00824252 /* Main.storyboard */; }; @@ -15,6 +17,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 956323AB22B2D049001505FB /* BronzeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BronzeViewController.swift; sourceTree = ""; }; + 956323AD22B2E0BC001505FB /* enviarNotificacao.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = enviarNotificacao.swift; sourceTree = ""; }; AA6671C522B1292D00824252 /* LocalNotificationBase.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LocalNotificationBase.app; sourceTree = BUILT_PRODUCTS_DIR; }; AA6671C822B1292D00824252 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; AA6671CA22B1292D00824252 /* BaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = ""; }; @@ -54,12 +58,14 @@ AA6671C722B1292D00824252 /* LocalNotificationBase */ = { isa = PBXGroup; children = ( + 956323AB22B2D049001505FB /* BronzeViewController.swift */, AA6671C822B1292D00824252 /* AppDelegate.swift */, AA6671CA22B1292D00824252 /* BaseViewController.swift */, AA6671CC22B1292D00824252 /* Main.storyboard */, AA6671CF22B1293000824252 /* Assets.xcassets */, AA6671D122B1293000824252 /* LaunchScreen.storyboard */, AA6671D422B1293000824252 /* Info.plist */, + 956323AD22B2E0BC001505FB /* enviarNotificacao.swift */, ); path = LocalNotificationBase; sourceTree = ""; @@ -136,7 +142,9 @@ buildActionMask = 2147483647; files = ( AA6671CB22B1292D00824252 /* BaseViewController.swift in Sources */, + 956323AC22B2D049001505FB /* BronzeViewController.swift in Sources */, AA6671C922B1292D00824252 /* AppDelegate.swift in Sources */, + 956323AE22B2E0BC001505FB /* enviarNotificacao.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/LocalNotificationBase.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/LocalNotificationBase.xcodeproj/project.xcworkspace/contents.xcworkspacedata old mode 100644 new mode 100755 diff --git a/LocalNotificationBase.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/LocalNotificationBase.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist old mode 100644 new mode 100755 diff --git a/LocalNotificationBase/AppDelegate.swift b/LocalNotificationBase/AppDelegate.swift old mode 100644 new mode 100755 index 07da379..275d352 --- a/LocalNotificationBase/AppDelegate.swift +++ b/LocalNotificationBase/AppDelegate.swift @@ -40,6 +40,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. + application.applicationIconBadgeNumber = 0 } func applicationDidBecomeActive(_ application: UIApplication) { diff --git a/LocalNotificationBase/Assets.xcassets/AppIcon.appiconset/Contents.json b/LocalNotificationBase/Assets.xcassets/AppIcon.appiconset/Contents.json old mode 100644 new mode 100755 diff --git a/LocalNotificationBase/Assets.xcassets/Contents.json b/LocalNotificationBase/Assets.xcassets/Contents.json old mode 100644 new mode 100755 diff --git a/LocalNotificationBase/Base.lproj/LaunchScreen.storyboard b/LocalNotificationBase/Base.lproj/LaunchScreen.storyboard old mode 100644 new mode 100755 diff --git a/LocalNotificationBase/Base.lproj/Main.storyboard b/LocalNotificationBase/Base.lproj/Main.storyboard old mode 100644 new mode 100755 index 0d2afb5..a326cb0 --- a/LocalNotificationBase/Base.lproj/Main.storyboard +++ b/LocalNotificationBase/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -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