diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..1ddd18b Binary files /dev/null and b/.DS_Store differ diff --git a/LocalNotificationBase.xcodeproj/project.pbxproj b/LocalNotificationBase.xcodeproj/project.pbxproj index dd7afac..23a1165 100644 --- a/LocalNotificationBase.xcodeproj/project.pbxproj +++ b/LocalNotificationBase.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 760B8A6422B2C740004E79C6 /* ChallengesTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 760B8A6322B2C740004E79C6 /* ChallengesTableViewController.swift */; }; + 76F355FB22B2EFC900D4DF1F /* SilverViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F355FA22B2EFC900D4DF1F /* SilverViewController.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 */ + 760B8A6322B2C740004E79C6 /* ChallengesTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChallengesTableViewController.swift; sourceTree = ""; }; + 76F355FA22B2EFC900D4DF1F /* SilverViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SilverViewController.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 +60,8 @@ children = ( AA6671C822B1292D00824252 /* AppDelegate.swift */, AA6671CA22B1292D00824252 /* BaseViewController.swift */, + 760B8A6322B2C740004E79C6 /* ChallengesTableViewController.swift */, + 76F355FA22B2EFC900D4DF1F /* SilverViewController.swift */, AA6671CC22B1292D00824252 /* Main.storyboard */, AA6671CF22B1293000824252 /* Assets.xcassets */, AA6671D122B1293000824252 /* LaunchScreen.storyboard */, @@ -135,6 +141,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 760B8A6422B2C740004E79C6 /* ChallengesTableViewController.swift in Sources */, + 76F355FB22B2EFC900D4DF1F /* SilverViewController.swift in Sources */, AA6671CB22B1292D00824252 /* BaseViewController.swift in Sources */, AA6671C922B1292D00824252 /* AppDelegate.swift in Sources */, ); @@ -283,7 +291,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = GT48V5L69E; + DEVELOPMENT_TEAM = 4BUKN8ST5B; INFOPLIST_FILE = LocalNotificationBase/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -301,7 +309,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = GT48V5L69E; + DEVELOPMENT_TEAM = 4BUKN8ST5B; INFOPLIST_FILE = LocalNotificationBase/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", diff --git a/LocalNotificationBase/AppDelegate.swift b/LocalNotificationBase/AppDelegate.swift index 07da379..416a63a 100644 --- a/LocalNotificationBase/AppDelegate.swift +++ b/LocalNotificationBase/AppDelegate.swift @@ -25,8 +25,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate { print("Notifications not allowed by user") } } + +// let repeatAction = UNNotificationAction(identifier: "repeat", title: "Repeat", options: []) +// let openAction = UNNotificationAction(identifier: "open", title: "Open", options: []) + return true } + func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. @@ -43,7 +48,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/Assets.xcassets/HelloThere.imageset/Contents.json b/LocalNotificationBase/Assets.xcassets/HelloThere.imageset/Contents.json new file mode 100644 index 0000000..39cec11 --- /dev/null +++ b/LocalNotificationBase/Assets.xcassets/HelloThere.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "HelloThere.jpg", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/LocalNotificationBase/Assets.xcassets/HelloThere.imageset/HelloThere.jpg b/LocalNotificationBase/Assets.xcassets/HelloThere.imageset/HelloThere.jpg new file mode 100644 index 0000000..d73e83a Binary files /dev/null and b/LocalNotificationBase/Assets.xcassets/HelloThere.imageset/HelloThere.jpg differ diff --git a/LocalNotificationBase/Base.lproj/Main.storyboard b/LocalNotificationBase/Base.lproj/Main.storyboard index 0d2afb5..1ab9adb 100644 --- a/LocalNotificationBase/Base.lproj/Main.storyboard +++ b/LocalNotificationBase/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -10,7 +10,7 @@ - + @@ -31,9 +31,267 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LocalNotificationBase/ChallengesTableViewController.swift b/LocalNotificationBase/ChallengesTableViewController.swift new file mode 100644 index 0000000..c436eef --- /dev/null +++ b/LocalNotificationBase/ChallengesTableViewController.swift @@ -0,0 +1,121 @@ +// +// ChallengesTableViewController.swift +// LocalNotificationBase +// +// Created by Leonardo Oliveira on 13/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import UIKit +import UserNotifications + +class ChallengesTableViewController: UITableViewController, UNUserNotificationCenterDelegate { + + @IBOutlet weak var titleTextField: UITextField! + @IBOutlet weak var textTextField: UITextField! + @IBOutlet weak var timeTextField: UITextField! + + @IBOutlet weak var soundSwitch: UISwitch! + @IBOutlet weak var badgeSwitch: UISwitch! + + var titleStr: String? + var textStr: String? + var time: Double? + + override func viewDidLoad() { + super.viewDidLoad() + + let tap = UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:))) + tap.cancelsTouchesInView = false + self.view.addGestureRecognizer(tap) + + UNUserNotificationCenter.current().delegate = self + } + + + @IBAction func sendBtnPressed(_ sender: Any) { + + titleStr = titleTextField.text! + + textStr = textTextField.text! + + time = 0.0 + + if timeTextField!.text != "0"{ + time = Double(self.timeTextField!.text!) as! Double + } + + if titleStr != "" && textStr != "" && timeTextField.text != "" { + + notification(title: titleStr!, text: textStr!, time: time!, sound: soundSwitch.isOn, badge: badgeSwitch.isOn) + + } else{ + + let alert = UIAlertController(title: "Incomplete or invalid data", message: nil, preferredStyle: UIAlertController.Style.alert) + + let fillLabelAction = UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil) + alert.addAction(fillLabelAction) + self.present(alert, animated: true, completion: nil) + } + } + + + func notification(title: String, text: String, time: Double, sound: Bool, badge: Bool){ + + let notificationCenter = UNUserNotificationCenter.current() + notificationCenter.getNotificationSettings { (settings) in + if settings.authorizationStatus == .authorized { + + let content = UNMutableNotificationContent() + content.categoryIdentifier = "notifications" + content.title = NSString.localizedUserNotificationString(forKey: title, arguments: nil) + content.body = NSString.localizedUserNotificationString(forKey: text, arguments: nil) + + if sound{ + content.sound = UNNotificationSound.default + } + + if badge{ + content.badge = 1 + } + + let repeatAction = UNNotificationAction(identifier: "repeat", title: "Repeat", options: []) + let openAction = UNNotificationAction(identifier: "open", title: "Open", options: [.foreground]) + + let category = UNNotificationCategory(identifier: "notifications", actions: [repeatAction, openAction], intentIdentifiers: [], options: []) + + notificationCenter.setNotificationCategories([category]) + + + let trigger = UNTimeIntervalNotificationTrigger(timeInterval: time, repeats: false) + + let request = UNNotificationRequest(identifier: "time", 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") + } + } + } + + func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { + + if response.actionIdentifier == "repeat"{ + + center.add(response.notification.request, withCompletionHandler: nil) + + } else if response.actionIdentifier == "open"{ + + // present(SilverViewController(), animated: false, completion: nil) + self.performSegue(withIdentifier: "segue", sender: self) + + } + } + +} diff --git a/LocalNotificationBase/SilverViewController.swift b/LocalNotificationBase/SilverViewController.swift new file mode 100644 index 0000000..c428695 --- /dev/null +++ b/LocalNotificationBase/SilverViewController.swift @@ -0,0 +1,30 @@ +// +// SilverViewController.swift +// LocalNotificationBase +// +// Created by Leonardo Oliveira on 13/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import UIKit + +class SilverViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + // Do any additional setup after loading the view. + } + + + /* + // 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. + } + */ + +}