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
Binary file added .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions LocalNotificationBase.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -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)",
Expand Down
4 changes: 4 additions & 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 All @@ -51,5 +52,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}




}


97 changes: 95 additions & 2 deletions 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="Lel-TW-dMJ">
<device id="retina6_1" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
Expand All @@ -10,6 +10,22 @@
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
<scene sceneID="DFC-d3-eCH">
<objects>
<navigationController id="Lel-TW-dMJ" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="Mtf-MB-TYS">
<rect key="frame" x="0.0" y="44" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="CeR-VV-J6E"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="eKi-lR-rbm" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-1597" y="-5"/>
</scene>
<!--Base View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
Expand All @@ -19,21 +35,98 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="wordWrap" translatesAutoresizingMaskIntoConstraints="NO" id="w9d-0c-pQf">
<rect key="frame" x="50" y="413" width="314" height="70"/>
<rect key="frame" x="50" y="495" width="314" height="70"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="48"/>
<state key="normal" title="Me lembre"/>
<connections>
<action selector="remindButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="A89-dm-q8u"/>
</connections>
</button>
<textField opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Titutlo da notificacao" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="bKb-Vp-WNn">
<rect key="frame" x="20" y="88" 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>
<textField opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="corpo da notificacao" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="6iA-qu-Ycq">
<rect key="frame" x="20" y="158" 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>
<pickerView contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="MAa-Uf-iFg">
<rect key="frame" x="0.0" y="180" width="414" height="162"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<connections>
<outlet property="dataSource" destination="BYZ-38-t0r" id="w32-D8-SNU"/>
<outlet property="delegate" destination="BYZ-38-t0r" id="aYL-R2-UPj"/>
</connections>
</pickerView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Sound" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="A77-CV-G8O">
<rect key="frame" x="20" y="347" 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>
<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="Dgu-Y3-TnS">
<rect key="frame" x="20" y="402" 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="zf8-Ww-022">
<rect key="frame" x="345" y="342" 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="Sr8-ak-0FX">
<rect key="frame" x="345" y="397" width="49" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</switch>
</subviews>
<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="Eyu-Db-Tc6"/>
<connections>
<outlet property="badgeBool" destination="Sr8-ak-0FX" id="3rM-2U-DAo"/>
<outlet property="bodyNotification" destination="6iA-qu-Ycq" id="o7b-w8-qY6"/>
<outlet property="soundBool" destination="zf8-Ww-022" id="ukt-f2-jya"/>
<outlet property="titleNotification" destination="bKb-Vp-WNn" id="7Uy-cr-ufD"/>
<segue destination="xrT-Ug-jiJ" kind="show" identifier="vcLembrou" id="8nO-vd-snY"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="46" y="-5"/>
</scene>
<!--View Controller-->
<scene sceneID="L3u-FJ-tEa">
<objects>
<viewController id="xrT-Ug-jiJ" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="3pZ-dd-aZf">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Vc lembrou" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="KSV-Pv-X9k">
<rect key="frame" x="105" y="424" width="205" height="49"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="41"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<viewLayoutGuide key="safeArea" id="Ob4-ik-U7R"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="r3p-S4-6dd" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="952" y="21"/>
</scene>
</scenes>
</document>
86 changes: 79 additions & 7 deletions LocalNotificationBase/BaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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{

}
}

}
Expand Down