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
34 changes: 29 additions & 5 deletions LocalNotificationBase.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
869E664C22B2C8A4000E5866 /* EditViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869E664B22B2C8A4000E5866 /* EditViewController.swift */; };
869E665022B2C958000E5866 /* sendNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869E664F22B2C958000E5866 /* sendNotification.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 */; };
Expand All @@ -15,6 +17,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
869E664B22B2C8A4000E5866 /* EditViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditViewController.swift; sourceTree = "<group>"; };
869E664F22B2C958000E5866 /* sendNotification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = sendNotification.swift; sourceTree = "<group>"; };
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 = "<group>"; };
AA6671CA22B1292D00824252 /* BaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = "<group>"; };
Expand All @@ -35,6 +39,25 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
869E664D22B2C8C3000E5866 /* View */ = {
isa = PBXGroup;
children = (
AA6671D122B1293000824252 /* LaunchScreen.storyboard */,
AA6671CC22B1292D00824252 /* Main.storyboard */,
);
path = View;
sourceTree = "<group>";
};
869E664E22B2C8CF000E5866 /* Controller */ = {
isa = PBXGroup;
children = (
869E664B22B2C8A4000E5866 /* EditViewController.swift */,
AA6671CA22B1292D00824252 /* BaseViewController.swift */,
869E664F22B2C958000E5866 /* sendNotification.swift */,
);
path = Controller;
sourceTree = "<group>";
};
AA6671BC22B1292D00824252 = {
isa = PBXGroup;
children = (
Expand All @@ -54,11 +77,10 @@
AA6671C722B1292D00824252 /* LocalNotificationBase */ = {
isa = PBXGroup;
children = (
869E664D22B2C8C3000E5866 /* View */,
869E664E22B2C8CF000E5866 /* Controller */,
AA6671C822B1292D00824252 /* AppDelegate.swift */,
AA6671CA22B1292D00824252 /* BaseViewController.swift */,
AA6671CC22B1292D00824252 /* Main.storyboard */,
AA6671CF22B1293000824252 /* Assets.xcassets */,
AA6671D122B1293000824252 /* LaunchScreen.storyboard */,
AA6671D422B1293000824252 /* Info.plist */,
);
path = LocalNotificationBase;
Expand Down Expand Up @@ -136,6 +158,8 @@
buildActionMask = 2147483647;
files = (
AA6671CB22B1292D00824252 /* BaseViewController.swift in Sources */,
869E664C22B2C8A4000E5866 /* EditViewController.swift in Sources */,
869E665022B2C958000E5866 /* sendNotification.swift in Sources */,
AA6671C922B1292D00824252 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -283,7 +307,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = GT48V5L69E;
DEVELOPMENT_TEAM = CTAFH43K36;
INFOPLIST_FILE = LocalNotificationBase/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -301,7 +325,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = GT48V5L69E;
DEVELOPMENT_TEAM = CTAFH43K36;
INFOPLIST_FILE = LocalNotificationBase/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down
1 change: 1 addition & 0 deletions LocalNotificationBase/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
39 changes: 0 additions & 39 deletions LocalNotificationBase/Base.lproj/Main.storyboard

This file was deleted.

47 changes: 0 additions & 47 deletions LocalNotificationBase/BaseViewController.swift

This file was deleted.

24 changes: 24 additions & 0 deletions LocalNotificationBase/Controller/BaseViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// 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) {
sendNotificationLocal("Lembre-se", "ocê se lembrou", "5", 5, true, 1)
}

}

83 changes: 83 additions & 0 deletions LocalNotificationBase/Controller/EditViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// editViewController.swift
// LocalNotificationBase
//
// Created by Matheus Gois on 13/06/19.
// Copyright © 2019 Bruno Omella Mainieri. All rights reserved.
//

import UIKit

class EditViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {


@IBOutlet weak var titleNotification: UITextField!
@IBOutlet weak var bodyNotification: UITextField!

@IBOutlet weak var changeTimePickerNotification: UIPickerView!
@IBOutlet weak var enableSoundNotification: UISwitch!
@IBOutlet weak var enableBadgeNotification: UISwitch!

var array = ["1","2","3","4","5","6","7","8","9","10"]
var timeSelected = ""

@IBAction func sendNotification(_ sender: UIButton) {
let title = titleNotification.text as! String
let body = bodyNotification.text as! String
let stateBadge = self.enableBadgeNotification.isOn
let stateSound = self.enableSoundNotification.isOn
guard let time = TimeInterval(self.timeSelected) else { return }

sendNotificationLocal(title, body, "1", time, stateSound, (stateBadge ? 1 : 0))

}

override func viewDidLoad() {
super.viewDidLoad()

timeSelected = array[0]

// Do any additional setup after loading the view.
self.changeTimePickerNotification.delegate = self
self.changeTimePickerNotification.dataSource = self
}



func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}

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

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
timeSelected = array[row]
}



}


//func stringFromTimeInterval (interval: String) -> TimeInterval {
// let endingDate = Date()
// if let timeInterval = TimeInterval(interval) {
// let startingDate = endingDate.addingTimeInterval(-timeInterval)
// let calendar = Calendar.current
//
// var componentsNow = calendar.dateComponents([.hour, .minute, .second], from: startingDate, to: endingDate)
// if let hour = componentsNow.hour, let minute = componentsNow.minute, let seconds = componentsNow.second {
// return "\(hour):\(minute):\(seconds)"
// } else {
// return "00:00:00"
// }
//
// } else {
// return "00:00:00"
// }
//}
39 changes: 39 additions & 0 deletions LocalNotificationBase/Controller/sendNotification.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// sendNotification.swift
// LocalNotificationBase
//
// Created by Matheus Gois on 13/06/19.
// Copyright © 2019 Bruno Omella Mainieri. All rights reserved.
//

import Foundation
import UserNotifications

func sendNotificationLocal(_ title:String, _ body:String, _ identifier: String, _ timeInterval:TimeInterval, _ sound:Bool, _ badge:NSNumber) -> Void{
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.getNotificationSettings { (settings) in
if settings.authorizationStatus == .authorized {

let content = UNMutableNotificationContent()
content.title = NSString.localizedUserNotificationString(forKey: title, arguments: nil)
content.body = NSString.localizedUserNotificationString(forKey: body, arguments: nil)

content.sound = sound ? UNNotificationSound.default : nil
content.badge = badge

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

let request = UNNotificationRequest(identifier: identifier, 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")
}
}
}
Loading