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..04c7ab1 --- a/LocalNotificationBase.xcodeproj/project.pbxproj +++ b/LocalNotificationBase.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 6DA9F0A222B2C08100EE6415 /* BronzeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DA9F0A122B2C08100EE6415 /* BronzeViewController.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 +16,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 6DA9F0A122B2C08100EE6415 /* BronzeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BronzeViewController.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 = ""; }; @@ -56,6 +58,7 @@ children = ( AA6671C822B1292D00824252 /* AppDelegate.swift */, AA6671CA22B1292D00824252 /* BaseViewController.swift */, + 6DA9F0A122B2C08100EE6415 /* BronzeViewController.swift */, AA6671CC22B1292D00824252 /* Main.storyboard */, AA6671CF22B1293000824252 /* Assets.xcassets */, AA6671D122B1293000824252 /* LaunchScreen.storyboard */, @@ -135,6 +138,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 6DA9F0A222B2C08100EE6415 /* BronzeViewController.swift in Sources */, AA6671CB22B1292D00824252 /* BaseViewController.swift in Sources */, AA6671C922B1292D00824252 /* AppDelegate.swift in Sources */, ); 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..84ff3c4 --- a/LocalNotificationBase/AppDelegate.swift +++ b/LocalNotificationBase/AppDelegate.swift @@ -43,6 +43,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } func applicationDidBecomeActive(_ application: UIApplication) { + UIApplication.shared.applicationIconBadgeNumber = 0 // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } 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..6ea714f --- a/LocalNotificationBase/Base.lproj/Main.storyboard +++ b/LocalNotificationBase/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -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