From 409a928b8237fc91f05f242a726d4ae9da2f03da Mon Sep 17 00:00:00 2001 From: iago salomon Date: Thu, 13 Jun 2019 17:56:48 -0300 Subject: [PATCH] prata pela metade --- .DS_Store | Bin 0 -> 6148 bytes .../project.pbxproj | 4 +- LocalNotificationBase/AppDelegate.swift | 4 + .../Base.lproj/Main.storyboard | 97 +++++++++++++++++- .../BaseViewController.swift | 86 ++++++++++++++-- 5 files changed, 180 insertions(+), 11 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..fb274c990e194f2fa6dcc15fd2e084702bf78d95 GIT binary patch literal 6148 zcmeHKOHKnZ41I^fID#{p6!4-Vs=QV zAX`eFW5-VNq)EmAqZuWvuk*xl}CeBVdjVo$+9 zFc1s`1AmtRzS%0{Bgg22fnXpQ_+mishs36sD;7t)I@nnWKpfF*LS1VKjY$=A#o|a0 zMLd+~p;Ai>@o?HxotG;XM-PYC%FI(&{w!X^R;NALbVzoLJ{SlF`V1WUaH8-389$l9 zBEKIJqhKHy_-72rXttO&JXC#Kza3BC+QfFjrlRwTDirFyp8yW@9yvCr`;+RNmn#-W U&7yV-C&rI}5fWW6@Cyul02{e2o&W#< literal 0 HcmV?d00001 diff --git a/LocalNotificationBase.xcodeproj/project.pbxproj b/LocalNotificationBase.xcodeproj/project.pbxproj index dd7afac..050e233 100644 --- a/LocalNotificationBase.xcodeproj/project.pbxproj +++ b/LocalNotificationBase.xcodeproj/project.pbxproj @@ -283,7 +283,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = GT48V5L69E; + DEVELOPMENT_TEAM = 4UR6BVKFQM; INFOPLIST_FILE = LocalNotificationBase/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -301,7 +301,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = GT48V5L69E; + DEVELOPMENT_TEAM = 4UR6BVKFQM; INFOPLIST_FILE = LocalNotificationBase/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", diff --git a/LocalNotificationBase/AppDelegate.swift b/LocalNotificationBase/AppDelegate.swift index 07da379..c307185 100644 --- 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) { @@ -51,5 +52,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } + + } + diff --git a/LocalNotificationBase/Base.lproj/Main.storyboard b/LocalNotificationBase/Base.lproj/Main.storyboard index 0d2afb5..3c74d48 100644 --- a/LocalNotificationBase/Base.lproj/Main.storyboard +++ b/LocalNotificationBase/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -10,6 +10,22 @@ + + + + + + + + + + + + + + + + @@ -19,7 +35,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LocalNotificationBase/BaseViewController.swift b/LocalNotificationBase/BaseViewController.swift index b3615fb..ff30c72 100644 --- a/LocalNotificationBase/BaseViewController.swift +++ b/LocalNotificationBase/BaseViewController.swift @@ -9,24 +9,79 @@ import UIKit import UserNotifications -class BaseViewController: UIViewController { +class BaseViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource, UNUserNotificationCenterDelegate { + + + let time = [1,2,3,4,5,6,7,8,9] + + + + + + @IBOutlet weak var titleNotification: UITextField! + @IBOutlet weak var bodyNotification: UITextField! + @IBOutlet weak var soundBool: UISwitch! + @IBOutlet weak var badgeBool: UISwitch! + + var titulo = "" + var corpo = "" + var som = false + var badge = false + var intervaloDeTempo = 0 + + var timer_for_notification = 0 + + func numberOfComponents(in pickerView: UIPickerView) -> Int { + return 1 + } + func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { + let Show = time[row] as NSNumber + return Show.stringValue + } + + func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { + return time.count + } + + func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { + timer_for_notification = time[row] + } + + override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } - - @IBAction func remindButton(_ sender: Any) { + + + func createNotifcation(){ + let repeatAction = UNNotificationAction(identifier: "repetir", title: "Repetir") + let okAction = UNNotificationAction(identifier: "ok", title: "ok", options: UNNotificationActionOptions.foreground) + + + let category = UNNotificationCategory(identifier: "Options", actions: [okAction,repeatAction], intentIdentifiers: [], options: []) + + let notificationCenter = UNUserNotificationCenter.current() + notificationCenter.setNotificationCategories([category]) + 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 + content.title = NSString.localizedUserNotificationString(forKey: self.titulo, arguments: nil) + content.body = NSString.localizedUserNotificationString(forKey: self.corpo, arguments: nil) + if self.som{ + content.sound = UNNotificationSound.default + } + content.categoryIdentifier = "Options" + if self.badge{ + content.badge = UIApplication.shared.applicationIconBadgeNumber + 1 as NSNumber + + } - let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false) + let trigger = UNTimeIntervalNotificationTrigger(timeInterval: TimeInterval(self.intervaloDeTempo), repeats: false) let request = UNNotificationRequest(identifier: "5seconds", content: content, trigger: trigger) @@ -41,6 +96,23 @@ class BaseViewController: UIViewController { print("Impossível mandar notificação - permissão negada") } } + + } + @IBAction func remindButton(_ sender: Any) { + titulo = self.titleNotification.text! + corpo = self.bodyNotification.text! + som = self.soundBool.isOn + badge = self.badgeBool.isOn + intervaloDeTempo = timer_for_notification + createNotifcation() + } + + func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { + if response.actionIdentifier == "repetir"{ + createNotifcation() + }else{ + + } } }