diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..b8866fe Binary files /dev/null and b/.DS_Store differ diff --git a/LocalNotificationBase.xcodeproj/project.pbxproj b/LocalNotificationBase.xcodeproj/project.pbxproj index dd7afac..ab8d236 100644 --- a/LocalNotificationBase.xcodeproj/project.pbxproj +++ b/LocalNotificationBase.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 87F0541C22B2C614008DAE9A /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87F0541B22B2C614008DAE9A /* TableViewController.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 */ + 87F0541B22B2C614008DAE9A /* TableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewController.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 = ""; }; @@ -57,6 +59,7 @@ AA6671C822B1292D00824252 /* AppDelegate.swift */, AA6671CA22B1292D00824252 /* BaseViewController.swift */, AA6671CC22B1292D00824252 /* Main.storyboard */, + 87F0541B22B2C614008DAE9A /* TableViewController.swift */, AA6671CF22B1293000824252 /* Assets.xcassets */, AA6671D122B1293000824252 /* LaunchScreen.storyboard */, AA6671D422B1293000824252 /* Info.plist */, @@ -136,6 +139,7 @@ buildActionMask = 2147483647; files = ( AA6671CB22B1292D00824252 /* BaseViewController.swift in Sources */, + 87F0541C22B2C614008DAE9A /* TableViewController.swift in Sources */, AA6671C922B1292D00824252 /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LocalNotificationBase/AppDelegate.swift b/LocalNotificationBase/AppDelegate.swift index 07da379..ec8167f 100644 --- a/LocalNotificationBase/AppDelegate.swift +++ b/LocalNotificationBase/AppDelegate.swift @@ -11,7 +11,7 @@ import UserNotifications @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { - + var window: UIWindow? diff --git a/LocalNotificationBase/Base.lproj/Main.storyboard b/LocalNotificationBase/Base.lproj/Main.storyboard index 0d2afb5..fe96489 100644 --- a/LocalNotificationBase/Base.lproj/Main.storyboard +++ b/LocalNotificationBase/Base.lproj/Main.storyboard @@ -27,6 +27,14 @@ + @@ -34,6 +42,182 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LocalNotificationBase/CollectionViewCell.swift b/LocalNotificationBase/CollectionViewCell.swift new file mode 100644 index 0000000..3ef035d --- /dev/null +++ b/LocalNotificationBase/CollectionViewCell.swift @@ -0,0 +1,14 @@ +// +// CollectionViewCell.swift +// LocalNotificationBase +// +// Created by Mariana Lima on 13/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import UIKit +import UserNotifications + +class CollectionViewCell: UICollectionViewCell { + +} diff --git a/LocalNotificationBase/TableViewController.swift b/LocalNotificationBase/TableViewController.swift new file mode 100644 index 0000000..30a4ed9 --- /dev/null +++ b/LocalNotificationBase/TableViewController.swift @@ -0,0 +1,89 @@ +// +// TableViewController.swift +// LocalNotificationBase +// +// Created by Mariana Lima on 13/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import UIKit +import UserNotifications + +class TableViewController: UITableViewController, UIPickerViewDelegate, UIPickerViewDataSource { + func numberOfComponents(in pickerView: UIPickerView) -> Int { + return 1 + } + + func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { + return conteudopicker.count + } + func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { + return conteudopicker [row] + } + + + @IBOutlet weak var titulobase: UITextField! + @IBOutlet weak var corpobase: UITextField! + @IBOutlet weak var segmentedControl: UISwitch! + @IBOutlet weak var segmentedControlNot: UISwitch! + @IBAction func enviar(_ sender: Any) { + + let content = UNMutableNotificationContent() + if segmentedControl.isOn { + + content.sound = UNNotificationSound.default + } + else { + + content.sound = nil + } + if segmentedControlNot.isOn{ + content.badge = true + } + else { + content.badge = false + } + + if let texto = self.titulobase.text { + content.title = NSString.localizedUserNotificationString(forKey: texto, arguments: nil) + } + + if let corpo = self.corpobase.text { + content.body = NSString.localizedUserNotificationString(forKey: corpo, arguments: nil) + } + + let trigger = UNTimeIntervalNotificationTrigger(timeInterval: TimeInterval(self.picker.selectedRow(inComponent: 0)), repeats: false) + + let notificationCenter = UNUserNotificationCenter.current() + notificationCenter.getNotificationSettings { (settings) in + if settings.authorizationStatus == .authorized { + + + 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") + } + } + + + + } + + @IBOutlet weak var picker: UIPickerView! + var conteudopicker : [String] = [String] () + + override func viewDidLoad() { + super.viewDidLoad() + conteudopicker = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"] + picker.delegate = self + picker.dataSource = self + } +}