diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..9dfb9ed Binary files /dev/null and b/.DS_Store differ diff --git a/Content/Base.lproj/MainInterface.storyboard b/Content/Base.lproj/MainInterface.storyboard new file mode 100644 index 0000000..b1268c0 --- /dev/null +++ b/Content/Base.lproj/MainInterface.storyboard @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Content/Info.plist b/Content/Info.plist new file mode 100644 index 0000000..8737bb7 --- /dev/null +++ b/Content/Info.plist @@ -0,0 +1,42 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + Content + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + XPC! + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + NSExtension + + NSExtensionAttributes + + UNNotificationExtensionCategory + + OURO_NOTIFICACOES + + UNNotificationExtensionInitialContentSizeRatio + 0.9399999999999999 + UNNotificationExtensionDefaultContentHidden + + + NSExtensionMainStoryboard + MainInterface + NSExtensionPointIdentifier + com.apple.usernotifications.content-extension + + + diff --git a/Content/NotificationViewController.swift b/Content/NotificationViewController.swift new file mode 100644 index 0000000..2a7ac38 --- /dev/null +++ b/Content/NotificationViewController.swift @@ -0,0 +1,29 @@ +// +// NotificationViewController.swift +// Content +// +// Created by Lia Kassardjian on 14/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import UIKit +import UserNotifications +import UserNotificationsUI + +class NotificationViewController: UIViewController, UNNotificationContentExtension { + + + @IBOutlet weak var imagem: UIImageView! + + @IBOutlet weak var label: UILabel! + + override func viewDidLoad() { + super.viewDidLoad() + // Do any required interface initialization here. + } + + func didReceive(_ notification: UNNotification) { + self.label?.text = notification.request.content.body + } + +} diff --git a/LocalNotificationBase.xcodeproj/project.pbxproj b/LocalNotificationBase.xcodeproj/project.pbxproj index dd7afac..37fa2c1 100644 --- a/LocalNotificationBase.xcodeproj/project.pbxproj +++ b/LocalNotificationBase.xcodeproj/project.pbxproj @@ -12,8 +12,41 @@ AA6671CE22B1292D00824252 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = AA6671CC22B1292D00824252 /* Main.storyboard */; }; AA6671D022B1293000824252 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = AA6671CF22B1293000824252 /* Assets.xcassets */; }; AA6671D322B1293000824252 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = AA6671D122B1293000824252 /* LaunchScreen.storyboard */; }; + E4A59A7F22B2C01700323085 /* BronzeTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4A59A7E22B2C01700323085 /* BronzeTableViewController.swift */; }; + E4A59A8122B2E59C00323085 /* PrataTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4A59A8022B2E59C00323085 /* PrataTableViewController.swift */; }; + E4A59A8322B4027300323085 /* OuroTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4A59A8222B4027300323085 /* OuroTableViewController.swift */; }; + E4A59AB922B4819200323085 /* UserNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4A59AB822B4819200323085 /* UserNotifications.framework */; }; + E4A59ABB22B4819200323085 /* UserNotificationsUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4A59ABA22B4819200323085 /* UserNotificationsUI.framework */; }; + E4A59ABE22B4819200323085 /* NotificationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4A59ABD22B4819200323085 /* NotificationViewController.swift */; }; + E4A59AC122B4819200323085 /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E4A59ABF22B4819200323085 /* MainInterface.storyboard */; }; + E4A59AC522B4819200323085 /* Content.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = E4A59AB622B4819200323085 /* Content.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + E4BE11B822B7F72C00DC0AD3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = AA6671CF22B1293000824252 /* Assets.xcassets */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + E4A59AC322B4819200323085 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = AA6671BD22B1292D00824252 /* Project object */; + proxyType = 1; + remoteGlobalIDString = E4A59AB522B4819200323085; + remoteInfo = Content; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + E4A59A9322B4805700323085 /* Embed App Extensions */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 13; + files = ( + E4A59AC522B4819200323085 /* Content.appex in Embed App Extensions */, + ); + name = "Embed App Extensions"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ 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 = ""; }; @@ -22,6 +55,17 @@ AA6671CF22B1293000824252 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; AA6671D222B1293000824252 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; AA6671D422B1293000824252 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + E4A59A7E22B2C01700323085 /* BronzeTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BronzeTableViewController.swift; sourceTree = ""; }; + E4A59A8022B2E59C00323085 /* PrataTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrataTableViewController.swift; sourceTree = ""; }; + E4A59A8222B4027300323085 /* OuroTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OuroTableViewController.swift; sourceTree = ""; }; + E4A59AA922B4815700323085 /* NotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = ""; }; + E4A59AAB22B4815700323085 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + E4A59AB622B4819200323085 /* Content.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = Content.appex; sourceTree = BUILT_PRODUCTS_DIR; }; + E4A59AB822B4819200323085 /* UserNotifications.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotifications.framework; path = System/Library/Frameworks/UserNotifications.framework; sourceTree = SDKROOT; }; + E4A59ABA22B4819200323085 /* UserNotificationsUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotificationsUI.framework; path = System/Library/Frameworks/UserNotificationsUI.framework; sourceTree = SDKROOT; }; + E4A59ABD22B4819200323085 /* NotificationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationViewController.swift; sourceTree = ""; }; + E4A59AC022B4819200323085 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/MainInterface.storyboard; sourceTree = ""; }; + E4A59AC222B4819200323085 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -32,6 +76,15 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + E4A59AB322B4819200323085 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + E4A59ABB22B4819200323085 /* UserNotificationsUI.framework in Frameworks */, + E4A59AB922B4819200323085 /* UserNotifications.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -39,6 +92,9 @@ isa = PBXGroup; children = ( AA6671C722B1292D00824252 /* LocalNotificationBase */, + E4A59AA822B4815700323085 /* Service */, + E4A59ABC22B4819200323085 /* Content */, + E4A59AB722B4819200323085 /* Frameworks */, AA6671C622B1292D00824252 /* Products */, ); sourceTree = ""; @@ -47,6 +103,7 @@ isa = PBXGroup; children = ( AA6671C522B1292D00824252 /* LocalNotificationBase.app */, + E4A59AB622B4819200323085 /* Content.appex */, ); name = Products; sourceTree = ""; @@ -56,6 +113,9 @@ children = ( AA6671C822B1292D00824252 /* AppDelegate.swift */, AA6671CA22B1292D00824252 /* BaseViewController.swift */, + E4A59A7E22B2C01700323085 /* BronzeTableViewController.swift */, + E4A59A8022B2E59C00323085 /* PrataTableViewController.swift */, + E4A59A8222B4027300323085 /* OuroTableViewController.swift */, AA6671CC22B1292D00824252 /* Main.storyboard */, AA6671CF22B1293000824252 /* Assets.xcassets */, AA6671D122B1293000824252 /* LaunchScreen.storyboard */, @@ -64,6 +124,34 @@ path = LocalNotificationBase; sourceTree = ""; }; + E4A59AA822B4815700323085 /* Service */ = { + isa = PBXGroup; + children = ( + E4A59AA922B4815700323085 /* NotificationService.swift */, + E4A59AAB22B4815700323085 /* Info.plist */, + ); + path = Service; + sourceTree = ""; + }; + E4A59AB722B4819200323085 /* Frameworks */ = { + isa = PBXGroup; + children = ( + E4A59AB822B4819200323085 /* UserNotifications.framework */, + E4A59ABA22B4819200323085 /* UserNotificationsUI.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + E4A59ABC22B4819200323085 /* Content */ = { + isa = PBXGroup; + children = ( + E4A59ABD22B4819200323085 /* NotificationViewController.swift */, + E4A59ABF22B4819200323085 /* MainInterface.storyboard */, + E4A59AC222B4819200323085 /* Info.plist */, + ); + path = Content; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -74,16 +162,35 @@ AA6671C122B1292D00824252 /* Sources */, AA6671C222B1292D00824252 /* Frameworks */, AA6671C322B1292D00824252 /* Resources */, + E4A59A9322B4805700323085 /* Embed App Extensions */, ); buildRules = ( ); dependencies = ( + E4A59AC422B4819200323085 /* PBXTargetDependency */, ); name = LocalNotificationBase; productName = LocalNotificationBase; productReference = AA6671C522B1292D00824252 /* LocalNotificationBase.app */; productType = "com.apple.product-type.application"; }; + E4A59AB522B4819200323085 /* Content */ = { + isa = PBXNativeTarget; + buildConfigurationList = E4A59AC622B4819200323085 /* Build configuration list for PBXNativeTarget "Content" */; + buildPhases = ( + E4A59AB222B4819200323085 /* Sources */, + E4A59AB322B4819200323085 /* Frameworks */, + E4A59AB422B4819200323085 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Content; + productName = Content; + productReference = E4A59AB622B4819200323085 /* Content.appex */; + productType = "com.apple.product-type.app-extension"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -97,6 +204,9 @@ AA6671C422B1292D00824252 = { CreatedOnToolsVersion = 10.2.1; }; + E4A59AB522B4819200323085 = { + CreatedOnToolsVersion = 10.2.1; + }; }; }; buildConfigurationList = AA6671C022B1292D00824252 /* Build configuration list for PBXProject "LocalNotificationBase" */; @@ -113,6 +223,7 @@ projectRoot = ""; targets = ( AA6671C422B1292D00824252 /* LocalNotificationBase */, + E4A59AB522B4819200323085 /* Content */, ); }; /* End PBXProject section */ @@ -128,6 +239,15 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + E4A59AB422B4819200323085 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E4BE11B822B7F72C00DC0AD3 /* Assets.xcassets in Resources */, + E4A59AC122B4819200323085 /* MainInterface.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -135,13 +255,32 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + E4A59A8122B2E59C00323085 /* PrataTableViewController.swift in Sources */, AA6671CB22B1292D00824252 /* BaseViewController.swift in Sources */, + E4A59A8322B4027300323085 /* OuroTableViewController.swift in Sources */, + E4A59A7F22B2C01700323085 /* BronzeTableViewController.swift in Sources */, AA6671C922B1292D00824252 /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; + E4A59AB222B4819200323085 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E4A59ABE22B4819200323085 /* NotificationViewController.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXTargetDependency section */ + E4A59AC422B4819200323085 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = E4A59AB522B4819200323085 /* Content */; + targetProxy = E4A59AC322B4819200323085 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + /* Begin PBXVariantGroup section */ AA6671CC22B1292D00824252 /* Main.storyboard */ = { isa = PBXVariantGroup; @@ -159,6 +298,14 @@ name = LaunchScreen.storyboard; sourceTree = ""; }; + E4A59ABF22B4819200323085 /* MainInterface.storyboard */ = { + isa = PBXVariantGroup; + children = ( + E4A59AC022B4819200323085 /* Base */, + ); + name = MainInterface.storyboard; + sourceTree = ""; + }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ @@ -281,9 +428,10 @@ AA6671D822B1293000824252 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = GT48V5L69E; + DEVELOPMENT_TEAM = 5HW626WUP4; INFOPLIST_FILE = LocalNotificationBase/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -299,9 +447,10 @@ AA6671D922B1293000824252 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = GT48V5L69E; + DEVELOPMENT_TEAM = 5HW626WUP4; INFOPLIST_FILE = LocalNotificationBase/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -314,6 +463,44 @@ }; name = Release; }; + E4A59AC722B4819200323085 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 5HW626WUP4; + INFOPLIST_FILE = Content/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@executable_path/../../Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = br.com.mackmobile.LocalNotificationBase.Content; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + E4A59AC822B4819200323085 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 5HW626WUP4; + INFOPLIST_FILE = Content/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@executable_path/../../Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = br.com.mackmobile.LocalNotificationBase.Content; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -335,6 +522,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + E4A59AC622B4819200323085 /* Build configuration list for PBXNativeTarget "Content" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E4A59AC722B4819200323085 /* Debug */, + E4A59AC822B4819200323085 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ }; rootObject = AA6671BD22B1292D00824252 /* Project object */; diff --git a/LocalNotificationBase/.DS_Store b/LocalNotificationBase/.DS_Store new file mode 100644 index 0000000..bb1c548 Binary files /dev/null and b/LocalNotificationBase/.DS_Store differ diff --git a/LocalNotificationBase/AppDelegate.swift b/LocalNotificationBase/AppDelegate.swift index 07da379..718d821 100644 --- a/LocalNotificationBase/AppDelegate.swift +++ b/LocalNotificationBase/AppDelegate.swift @@ -43,7 +43,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/medalhaOuro.imageset/Contents.json b/LocalNotificationBase/Assets.xcassets/medalhaOuro.imageset/Contents.json new file mode 100644 index 0000000..0018daf --- /dev/null +++ b/LocalNotificationBase/Assets.xcassets/medalhaOuro.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "medalhaOuro.png", + "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/medalhaOuro.imageset/medalhaOuro.png b/LocalNotificationBase/Assets.xcassets/medalhaOuro.imageset/medalhaOuro.png new file mode 100644 index 0000000..2d04e7d Binary files /dev/null and b/LocalNotificationBase/Assets.xcassets/medalhaOuro.imageset/medalhaOuro.png differ diff --git a/LocalNotificationBase/Base.lproj/Main.storyboard b/LocalNotificationBase/Base.lproj/Main.storyboard index 0d2afb5..08e96e3 100644 --- a/LocalNotificationBase/Base.lproj/Main.storyboard +++ b/LocalNotificationBase/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -10,7 +10,7 @@ - + @@ -31,9 +31,799 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LocalNotificationBase/BronzeTableViewController.swift b/LocalNotificationBase/BronzeTableViewController.swift new file mode 100644 index 0000000..2121534 --- /dev/null +++ b/LocalNotificationBase/BronzeTableViewController.swift @@ -0,0 +1,127 @@ +// +// BronzeTableViewController.swift +// LocalNotificationBase +// +// Created by Lia Kassardjian on 13/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import UIKit +import UserNotifications + +class BronzeTableViewController: UITableViewController, UIPickerViewDelegate, UIPickerViewDataSource { + + @IBOutlet weak var tituloTextField: UITextField! + @IBOutlet weak var descricaoTextField: UITextField! + @IBOutlet weak var pickerTableViewCell: UITableViewCell! + @IBOutlet weak var tempoPickerView: UIPickerView! + @IBOutlet weak var somSwitch: UISwitch! + @IBOutlet weak var badgeSwitch: UISwitch! + + var valoresPicker:[Double] = [] + + override func viewDidLoad() { + tableView.tableFooterView = UIView(frame: CGRect.zero) + + super.viewDidLoad() + + self.tempoPickerView.delegate = self + self.tempoPickerView.dataSource = self + gerarNumeros() + } + + @IBAction func agendarButton(_ sender: Any) { + + let titulo:String = leTextField(textField: self.tituloTextField) + let descricao:String = leTextField(textField: self.descricaoTextField) + var tempo:Double = 0 + var som = true + var badge = true + + if let tempoPV = self.tempoPickerView { + tempo = self.valoresPicker[tempoPV.selectedRow(inComponent: 0)] + } + + if let somS = self.somSwitch { + if !somS.isOn { + som = false + } + } + + if let badgeS = self.badgeSwitch { + if !badgeS.isOn { + badge = false + } + } + + enviaNotificacao(titulo: titulo, descricao: descricao, tempo: tempo, som: som, badge: badge) + } + + func enviaNotificacao(titulo: String, descricao: String, tempo: Double, som: Bool, badge: Bool) { + let content = UNMutableNotificationContent() + content.title = titulo + content.body = descricao + + if som { + content.sound = UNNotificationSound.default + } else { + content.sound = .none + } + + if badge { + content.badge = UIApplication.shared.applicationIconBadgeNumber + 1 as NSNumber + } + + let trigger = UNTimeIntervalNotificationTrigger(timeInterval: tempo, repeats: false) + + let request = UNNotificationRequest(identifier: "bronze", content: content, trigger: trigger) + + + let notificationCenter = UNUserNotificationCenter.current() + notificationCenter.getNotificationSettings { (settings) in + if settings.authorizationStatus == .authorized { + + 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 leTextField(textField: UITextField?) -> String { + if let tf = textField { + if let texto = tf.text{ + return texto + } + } + return "" + } + + func gerarNumeros() { + if valoresPicker.isEmpty { + for i in 1...60 { + valoresPicker.append(Double(i)) + } + } + } + + func numberOfComponents(in pickerView: UIPickerView) -> Int { + return 1 + } + + func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { + return valoresPicker.count + } + + + func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { + return String(format: "%.0f", valoresPicker[row]) + } + +} diff --git a/LocalNotificationBase/OuroTableViewController.swift b/LocalNotificationBase/OuroTableViewController.swift new file mode 100644 index 0000000..9bebb31 --- /dev/null +++ b/LocalNotificationBase/OuroTableViewController.swift @@ -0,0 +1,170 @@ +// +// OuroTableViewController.swift +// LocalNotificationBase +// +// Created by Lia Kassardjian on 14/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import UIKit +import UserNotifications + +class OuroTableViewController: UITableViewController, UIPickerViewDelegate, UIPickerViewDataSource, UNUserNotificationCenterDelegate{ + + @IBOutlet weak var tituloTextField: UITextField! + @IBOutlet weak var descricaoTextField: UITextField! + @IBOutlet weak var tempoPickerView: UIPickerView! + @IBOutlet weak var somSwitch: UISwitch! + @IBOutlet weak var badgeSwitch: UISwitch! + + var valoresPicker:[Double] = [] + + override func viewDidLoad() { + tableView.tableFooterView = UIView(frame: CGRect.zero) + + super.viewDidLoad() + + self.tempoPickerView.delegate = self + self.tempoPickerView.dataSource = self + gerarNumeros() + } + + @IBAction func agendarButton(_ sender: Any) { + chamaNotificacao() + } + + func chamaNotificacao() { + let titulo:String = leTextField(textField: self.tituloTextField) + let descricao:String = leTextField(textField: self.descricaoTextField) + var tempo:Double = 0 + var som = true + var badge = true + + if let tempoPV = self.tempoPickerView { + tempo = self.valoresPicker[tempoPV.selectedRow(inComponent: 0)] + } + + if let somS = self.somSwitch { + if !somS.isOn { + som = false + } + } + + if let badgeS = self.badgeSwitch { + if !badgeS.isOn { + badge = false + } + } + + configuraNotificacao(titulo: titulo, descricao: descricao, tempo: tempo, som: som, badge: badge) + } + + func configuraNotificacao (titulo: String, descricao: String, tempo: Double, som: Bool, badge: Bool) { + let repetir = UNNotificationAction(identifier: "REPETIR", + title: "Repetir", + options: UNNotificationActionOptions(rawValue: 0)) + + let concluir = UNNotificationAction(identifier: "CONCLUIR", + title: "Ok", + options: [.foreground]) + + let categoriaOuro = UNNotificationCategory(identifier: "OURO_NOTIFICACOES", + actions: [repetir, concluir], + intentIdentifiers: [], + options: .customDismissAction) + + let content = UNMutableNotificationContent() + content.title = titulo + content.body = descricao + content.categoryIdentifier = "OURO_NOTIFICACOES" + + if som { + content.sound = UNNotificationSound.default + } else { + content.sound = .none + } + + if badge { + content.badge = UIApplication.shared.applicationIconBadgeNumber + 1 as NSNumber + } + + let trigger = UNTimeIntervalNotificationTrigger(timeInterval: tempo, repeats: false) + + let request = UNNotificationRequest(identifier: "ouro", content: content, trigger: trigger) + + enviaNotificacao(request: request, categoria: categoriaOuro) + } + + func enviaNotificacao(request: UNNotificationRequest, categoria: UNNotificationCategory) { + let notificationCenter = UNUserNotificationCenter.current() + notificationCenter.delegate = self + + notificationCenter.setNotificationCategories([categoria]) + + notificationCenter.getNotificationSettings { (settings) in + if settings.authorizationStatus == .authorized { + + 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) { + let content = response.notification.request.content + if content.categoryIdentifier == + "PRATA_NOTIFICACOES" { + } + + switch response.actionIdentifier { + case "REPETIR": + chamaNotificacao() + break + + case "CONCLUIR": + self.performSegue(withIdentifier: "conclusao", sender: nil) + break + + default: + break + } + } + + func leTextField(textField: UITextField?) -> String { + if let tf = textField { + if let texto = tf.text{ + return texto + } + } + return "" + } + + func gerarNumeros() { + if valoresPicker.isEmpty { + for i in 1...60 { + valoresPicker.append(Double(i)) + } + } + } + + func numberOfComponents(in pickerView: UIPickerView) -> Int { + return 1 + } + + func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { + return valoresPicker.count + } + + + func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { + return String(format: "%.0f", valoresPicker[row]) + } + +} diff --git a/LocalNotificationBase/PrataTableViewController.swift b/LocalNotificationBase/PrataTableViewController.swift new file mode 100644 index 0000000..c2d5fc2 --- /dev/null +++ b/LocalNotificationBase/PrataTableViewController.swift @@ -0,0 +1,170 @@ +// +// BronzeTableViewController.swift +// LocalNotificationBase +// +// Created by Lia Kassardjian on 13/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import UIKit +import UserNotifications + +class PrataTableViewController: UITableViewController, UIPickerViewDelegate, UIPickerViewDataSource, UNUserNotificationCenterDelegate { + + @IBOutlet weak var tituloTextField: UITextField! + @IBOutlet weak var descricaoTextField: UITextField! + @IBOutlet weak var tempoPickerView: UIPickerView! + @IBOutlet weak var somSwitch: UISwitch! + @IBOutlet weak var badgeSwitch: UISwitch! + + var valoresPicker:[Double] = [] + + override func viewDidLoad() { + tableView.tableFooterView = UIView(frame: CGRect.zero) + + super.viewDidLoad() + + self.tempoPickerView.delegate = self + self.tempoPickerView.dataSource = self + gerarNumeros() + } + + @IBAction func agendarButton(_ sender: Any) { + chamaNotificacao() + } + + func chamaNotificacao() { + let titulo:String = leTextField(textField: self.tituloTextField) + let descricao:String = leTextField(textField: self.descricaoTextField) + var tempo:Double = 0 + var som = true + var badge = true + + if let tempoPV = self.tempoPickerView { + tempo = self.valoresPicker[tempoPV.selectedRow(inComponent: 0)] + } + + if let somS = self.somSwitch { + if !somS.isOn { + som = false + } + } + + if let badgeS = self.badgeSwitch { + if !badgeS.isOn { + badge = false + } + } + + configuraNotificacao(titulo: titulo, descricao: descricao, tempo: tempo, som: som, badge: badge) + } + + func configuraNotificacao (titulo: String, descricao: String, tempo: Double, som: Bool, badge: Bool) { + let repetir = UNNotificationAction(identifier: "REPETIR", + title: "Repetir", + options: UNNotificationActionOptions(rawValue: 0)) + + let concluir = UNNotificationAction(identifier: "CONCLUIR", + title: "Ok", + options: [.foreground]) + + let categoriaOuro = UNNotificationCategory(identifier: "PRATA_NOTIFICACOES", + actions: [repetir, concluir], + intentIdentifiers: [], + options: .customDismissAction) + + let content = UNMutableNotificationContent() + content.title = titulo + content.body = descricao + content.categoryIdentifier = "PRATA_NOTIFICACOES" + + if som { + content.sound = UNNotificationSound.default + } else { + content.sound = .none + } + + if badge { + content.badge = UIApplication.shared.applicationIconBadgeNumber + 1 as NSNumber + } + + let trigger = UNTimeIntervalNotificationTrigger(timeInterval: tempo, repeats: false) + + let request = UNNotificationRequest(identifier: "prata", content: content, trigger: trigger) + + enviaNotificacao(request: request, categoria: categoriaOuro) + } + + func enviaNotificacao(request: UNNotificationRequest, categoria: UNNotificationCategory) { + let notificationCenter = UNUserNotificationCenter.current() + notificationCenter.delegate = self + + notificationCenter.setNotificationCategories([categoria]) + + notificationCenter.getNotificationSettings { (settings) in + if settings.authorizationStatus == .authorized { + + 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) { + let content = response.notification.request.content + if content.categoryIdentifier == + "PRATA_NOTIFICACOES" { + } + + switch response.actionIdentifier { + case "REPETIR": + chamaNotificacao() + break + + case "CONCLUIR": + self.performSegue(withIdentifier: "conclusao", sender: nil) + break + + default: + break + } + } + + func leTextField(textField: UITextField?) -> String { + if let tf = textField { + if let texto = tf.text{ + return texto + } + } + return "" + } + + func gerarNumeros() { + if valoresPicker.isEmpty { + for i in 1...60 { + valoresPicker.append(Double(i)) + } + } + } + + func numberOfComponents(in pickerView: UIPickerView) -> Int { + return 1 + } + + func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { + return valoresPicker.count + } + + + func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { + return String(format: "%.0f", valoresPicker[row]) + } + +} diff --git a/Service/Info.plist b/Service/Info.plist new file mode 100644 index 0000000..a986311 --- /dev/null +++ b/Service/Info.plist @@ -0,0 +1,31 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + Service + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + XPC! + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + NSExtension + + NSExtensionPointIdentifier + com.apple.usernotifications.service + NSExtensionPrincipalClass + $(PRODUCT_MODULE_NAME).NotificationService + + + diff --git a/Service/NotificationService.swift b/Service/NotificationService.swift new file mode 100644 index 0000000..97ab27b --- /dev/null +++ b/Service/NotificationService.swift @@ -0,0 +1,35 @@ +// +// NotificationService.swift +// Service +// +// Created by Lia Kassardjian on 14/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import UserNotifications + +class NotificationService: UNNotificationServiceExtension { + + var contentHandler: ((UNNotificationContent) -> Void)? + var bestAttemptContent: UNMutableNotificationContent? + + override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { + self.contentHandler = contentHandler + bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) + + if let bestAttemptContent = bestAttemptContent { + // Modify the notification content here... + bestAttemptContent.title = "\(bestAttemptContent.title) [modified]" + + contentHandler(bestAttemptContent) + } + } + + override func serviceExtensionTimeWillExpire() { + // Called just before the extension will be terminated by the system. + // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used. + if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent { + contentHandler(bestAttemptContent) + } + } +}