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
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
127 changes: 126 additions & 1 deletion LocalNotificationBase/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="b3r-zO-pQx">
<device id="retina6_1" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
Expand Down Expand Up @@ -31,9 +31,134 @@
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
<navigationItem key="navigationItem" id="UIH-VG-vre">
<barButtonItem key="rightBarButtonItem" style="plain" id="b8U-at-6ke">
<button key="customView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="h2E-RL-reC">
<rect key="frame" x="270" y="3" width="124" height="38"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="21"/>
<state key="normal" title="Configuração"/>
<connections>
<segue destination="saR-v8-7gN" kind="show" id="Zbz-uS-5sf"/>
</connections>
</button>
</barButtonItem>
</navigationItem>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="444.92753623188412" y="65.625"/>
</scene>
<!--Configuracao-->
<scene sceneID="axB-Xp-ayC">
<objects>
<viewController id="saR-v8-7gN" customClass="Configuracao" customModule="LocalNotificationBase" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="xgr-hb-lG5">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="nXL-v3-Mtc">
<rect key="frame" x="20" y="129" width="374" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Título" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="RkJ-dL-EO2">
<rect key="frame" x="20" y="100" width="43" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="I7E-L3-kVL">
<rect key="frame" x="20" y="196" width="374" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Corpo" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="IdI-fG-g4T">
<rect key="frame" x="20" y="167" width="48" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<pickerView contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="pqJ-2m-f5j">
<rect key="frame" x="20" y="263" width="374" height="162"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
</pickerView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Tempo" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="oTO-DY-20s">
<rect key="frame" x="20" y="234" width="53" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="B8L-hQ-TkB">
<rect key="frame" x="173" y="531" width="69" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Confirmar"/>
<connections>
<action selector="doneButton:" destination="saR-v8-7gN" eventType="touchUpInside" id="ijU-42-HMl"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Som" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="872-RE-0mQ">
<rect key="frame" x="20" y="433" width="35" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Badge" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4aK-rC-UBi">
<rect key="frame" x="20" y="472" width="50" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="cE2-lw-8Hx">
<rect key="frame" x="347" y="433" width="49" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</switch>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="n8w-MI-zL2">
<rect key="frame" x="347" y="472" width="49" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</switch>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<viewLayoutGuide key="safeArea" id="Ka6-pE-pLW"/>
</view>
<connections>
<outlet property="badgeSwitch" destination="n8w-MI-zL2" id="fbq-x6-nSg"/>
<outlet property="bodyNotification" destination="I7E-L3-kVL" id="LF4-zb-Fei"/>
<outlet property="pickerTimeWating" destination="pqJ-2m-f5j" id="ihY-oX-xEG"/>
<outlet property="soundSwitch" destination="cE2-lw-8Hx" id="GOQ-nr-kFl"/>
<outlet property="titleNotification" destination="nXL-v3-Mtc" id="bcp-fn-Ovn"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="mqU-AW-bbu" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1195.6521739130435" y="65.625"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="jF7-oh-D7g">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="b3r-zO-pQx" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="wOI-gl-cdA">
<rect key="frame" x="0.0" y="44" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="WzQ-IA-qqf"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="gon-yE-R8i" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-465.21739130434787" y="65.625"/>
</scene>
</scenes>
</document>
25 changes: 1 addition & 24 deletions LocalNotificationBase/BaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,7 @@ class BaseViewController: UIViewController {
}

@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")
}
}
editarNotificacao("Teste", "Des teste", "qualquercoisa", 5, 1, true)
}

}
Expand Down
55 changes: 55 additions & 0 deletions LocalNotificationBase/Configuracao.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// Configuracao.swift
// LocalNotificationBase
//
// Created by Fabrício Guilhermo on 13/06/19.
// Copyright © 2019 Bruno Omella Mainieri. All rights reserved.
//

import UIKit

class Configuracao: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {


@IBOutlet weak var titleNotification: UITextField!
@IBOutlet weak var bodyNotification: UITextField!
@IBOutlet weak var pickerTimeWating: UIPickerView!
@IBOutlet weak var soundSwitch: UISwitch!
@IBOutlet weak var badgeSwitch: UISwitch!

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

var pickerSelected = ""

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

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return elem.count
}

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

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

@IBAction func doneButton(_ sender: Any) {
let title = self.titleNotification.text as! String
let body = self.bodyNotification.text as! String
let sound = self.soundSwitch.isOn
let badge = self.badgeSwitch.isOn
guard let time = TimeInterval(pickerSelected) else { return }
editarNotificacao(title, body, "", time, badge ? 1 : 0, sound)
}

override func viewDidLoad() {
super.viewDidLoad()
pickerSelected = elem[0]
self.pickerTimeWating.delegate = self
self.pickerTimeWating.dataSource = self
}
}
45 changes: 45 additions & 0 deletions LocalNotificationBase/editNotification.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// editNotification.swift
// LocalNotificationBase
//
// Created by Fabrício Guilhermo on 13/06/19.
// Copyright © 2019 Bruno Omella Mainieri. All rights reserved.
//

import UIKit
import UserNotifications

func editarNotificacao(_ title:String, _ body:String, _ identifier:String, _ time: TimeInterval, _ notificationBall:NSNumber, _ sound:Bool) -> Void {

let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.getNotificationSettings { (settings) in
if settings.authorizationStatus == .authorized {

// var titulo:String
// var conteudo:String

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

content.sound = sound ? UNNotificationSound.default : nil

content.badge = notificationBall

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: time, 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")
}
}
}