Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// AppDelegate.swift
// LocalNotificationBase
//
// Created by Bruno Omella Mainieri on 12/06/19.
// Copyright © 2019 Bruno Omella Mainieri. All rights reserved.
//

import UIKit
import UserNotifications

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let options: UNAuthorizationOptions = [.alert,.sound,.badge]
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.requestAuthorization(options: options) {
(didAllow, error) in
if !didAllow {
print("Notifications not allowed by user")
}
}
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.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

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.
}

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.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

47 changes: 47 additions & 0 deletions BaseViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// ViewController.swift
// LocalNotificationBase
//
// Created by Bruno Omella Mainieri on 12/06/19.
// Copyright © 2019 Bruno Omella Mainieri. All rights reserved.
//

import UIKit
import UserNotifications

class BaseViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}

@IBAction func remindButton(_ sender: Any) {
let notificationCenter = UNUserNotificationCenter.current()
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

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)

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")
}
}
}

}

123 changes: 123 additions & 0 deletions BronzeNotificationTableViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
//
// BronzeNotificationTableViewController.swift
// LocalNotificationBase
//
// Created by Julia Santos on 13/06/19.
// Copyright © 2019 Bruno Omella Mainieri. All rights reserved.
//

import UIKit
import UserNotifications

class BronzeNotificationTableViewController: UITableViewController, UIPickerViewDelegate, UIPickerViewDataSource {
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerTimeData.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return pickerTimeData[row]
}

@IBOutlet weak var titulo: UITextField!

@IBOutlet weak var corpo: UITextField!

@IBOutlet weak var labelTempo: UILabel!

@IBOutlet weak var picker: UIPickerView!

@IBOutlet weak var labelSom: UILabel!

@IBOutlet weak var labelBadge: UILabel!

@IBOutlet weak var segmentedControlBadge: UISwitch!


@IBOutlet weak var segmentedControl: UISwitch!



@IBAction func button(_ sender: Any) {

let content = UNMutableNotificationContent()
if segmentedControlBadge.isOn {
content.badge = true
}else{
content.badge = false
}
if segmentedControl.isOn {
// let content = UNMutableNotificationContent()
content.sound = UNNotificationSound.default
}
else{
// let content = UNMutableNotificationContent()
content.sound = nil
}


if let texto = self.titulo.text {
content.title = NSString.localizedUserNotificationString(forKey: texto, arguments: nil)
}

if let bodyy = self.corpo.text{
content.body = NSString.localizedUserNotificationString(forKey: bodyy, 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")
}
}
}

var pickerTimeData: [String] = [String]()

var celulaEstaGrande:Bool = false

override func viewDidLoad() {
super.viewDidLoad()
pickerTimeData = ["1", "2", "3", "4", "5", "6", "7", "8"]
self.picker.delegate = self
self.picker.dataSource = self
}

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.section == 1 && indexPath.row == 0 {
if celulaEstaGrande {
return 250
}
else {
return 44
}
}
return 44
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 1 && indexPath.row == 0{
celulaEstaGrande = !celulaEstaGrande
tableView.beginUpdates()
tableView.endUpdates()
}
}
}
Binary file added LocalNotificationBase.xcodeproj.zip
Binary file not shown.