diff --git a/LocalNotificationBase.xcodeproj/project.pbxproj b/LocalNotificationBase.xcodeproj/project.pbxproj index dd7afac..fa49dff 100644 --- a/LocalNotificationBase.xcodeproj/project.pbxproj +++ b/LocalNotificationBase.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 0F44452D22B2C4CF00BEF9FB /* BronzeContorller.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F44452C22B2C4CF00BEF9FB /* BronzeContorller.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 */ + 0F44452C22B2C4CF00BEF9FB /* BronzeContorller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BronzeContorller.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 */, + 0F44452C22B2C4CF00BEF9FB /* BronzeContorller.swift */, AA6671CC22B1292D00824252 /* Main.storyboard */, AA6671CF22B1293000824252 /* Assets.xcassets */, AA6671D122B1293000824252 /* LaunchScreen.storyboard */, @@ -136,6 +139,7 @@ buildActionMask = 2147483647; files = ( AA6671CB22B1292D00824252 /* BaseViewController.swift in Sources */, + 0F44452D22B2C4CF00BEF9FB /* BronzeContorller.swift in Sources */, AA6671C922B1292D00824252 /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LocalNotificationBase/AppDelegate.swift b/LocalNotificationBase/AppDelegate.swift index 07da379..ad34ac9 100644 --- a/LocalNotificationBase/AppDelegate.swift +++ b/LocalNotificationBase/AppDelegate.swift @@ -44,6 +44,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func applicationDidBecomeActive(_ application: UIApplication) { // 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. + UIApplication.shared.applicationIconBadgeNumber = 0 } func applicationWillTerminate(_ application: UIApplication) { diff --git a/LocalNotificationBase/Base.lproj/Main.storyboard b/LocalNotificationBase/Base.lproj/Main.storyboard index 0d2afb5..80fbe2b 100644 --- a/LocalNotificationBase/Base.lproj/Main.storyboard +++ b/LocalNotificationBase/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -10,11 +10,11 @@ - - + + - - + + @@ -24,16 +24,183 @@ - + - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LocalNotificationBase/BronzeContorller.swift b/LocalNotificationBase/BronzeContorller.swift new file mode 100644 index 0000000..8854f94 --- /dev/null +++ b/LocalNotificationBase/BronzeContorller.swift @@ -0,0 +1,88 @@ +// +// BronzeContorller.swift +// LocalNotificationBase +// +// Created by Juliana Vigato Pavan on 13/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import Foundation +import UserNotifications +import UIKit + +class BronzeController: UITableViewController, UIPickerViewDelegate, UIPickerViewDataSource{ + + //number of columns of data + func numberOfComponents(in pickerView: UIPickerView) -> Int { + return 1 + } + + //number of rows of data + 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] + } + + + var pickerData: [String] = [String]() + + override func viewDidLoad() { + super.viewDidLoad() + + pickerData = ["1","2","3","4","5","6","7","8","9","10"] + + self.pickerViewTime.delegate = self + self.pickerViewTime.dataSource = self + } + + @IBOutlet weak var TitleLabel: UITextField! + @IBOutlet weak var BodyLabel: UITextField! + @IBOutlet weak var pickerViewTime: UIPickerView! + + @IBOutlet weak var SoundSwitch: UISwitch! + + @IBOutlet weak var BadgeSwitch: UISwitch! + + + @IBAction func SubmitButton(_ sender: Any) { + let notificationCnter = UNUserNotificationCenter.current() + let content = UNMutableNotificationContent() + if let titleText = self.TitleLabel.text{ + content.title = NSString.localizedUserNotificationString(forKey: titleText, arguments: nil) + } + if let bodyText = self.BodyLabel.text{ + content.body = NSString.localizedUserNotificationString(forKey: bodyText, arguments: nil) + } + + if SoundSwitch.isOn{ + content.sound = UNNotificationSound.default + } + + if BadgeSwitch.isOn{ + content.badge = 1 + } + + + let trigger = UNTimeIntervalNotificationTrigger(timeInterval: TimeInterval((pickerViewTime.selectedRow(inComponent: 0))+1), repeats: false) + + let request = UNNotificationRequest(identifier: "Time notification", content: content, trigger: trigger) + + notificationCnter.getNotificationSettings{ (settings) in + if settings.authorizationStatus == .authorized{ + let center = UNUserNotificationCenter.current() + center.add(request) { (error : Error?) in + if let error = error { + print(error.localizedDescription) + } + } + } else{ + print("Impossivel mandar notificacao!") + } + } + } +} + + diff --git a/LocalNotificationBase/ExBronze.swift b/LocalNotificationBase/ExBronze.swift new file mode 100644 index 0000000..8c5b2e0 --- /dev/null +++ b/LocalNotificationBase/ExBronze.swift @@ -0,0 +1,9 @@ +// +// ExBronze.swift +// LocalNotificationBase +// +// Created by Juliana Vigato Pavan on 13/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import Foundation