diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/.DS_Store differ diff --git a/Assets.xcassets/AppIcon.appiconset/Contents.json b/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d8db8d6 --- /dev/null +++ b/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Assets.xcassets/Contents.json b/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Assets.xcassets/Tony.imageset/Contents.json b/Assets.xcassets/Tony.imageset/Contents.json new file mode 100644 index 0000000..da4d2c5 --- /dev/null +++ b/Assets.xcassets/Tony.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "Tony.jpg", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Assets.xcassets/Tony.imageset/Tony.jpg b/Assets.xcassets/Tony.imageset/Tony.jpg new file mode 100644 index 0000000..80cc8b1 Binary files /dev/null and b/Assets.xcassets/Tony.imageset/Tony.jpg differ diff --git a/LocalNotificationBase.xcodeproj/project.pbxproj b/LocalNotificationBase.xcodeproj/project.pbxproj index dd7afac..a199a89 100644 --- a/LocalNotificationBase.xcodeproj/project.pbxproj +++ b/LocalNotificationBase.xcodeproj/project.pbxproj @@ -7,6 +7,13 @@ objects = { /* Begin PBXBuildFile section */ + 1E33A95F22B2C221003C5AA7 /* ChallengesTVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E33A95E22B2C221003C5AA7 /* ChallengesTVC.swift */; }; + 1E33A96722B2E3DB003C5AA7 /* UserNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1E33A96622B2E3DB003C5AA7 /* UserNotifications.framework */; }; + 1E33A96922B2E3DB003C5AA7 /* UserNotificationsUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1E33A96822B2E3DB003C5AA7 /* UserNotificationsUI.framework */; }; + 1E33A96C22B2E3DB003C5AA7 /* NotificationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E33A96B22B2E3DB003C5AA7 /* NotificationViewController.swift */; }; + 1E33A96F22B2E3DB003C5AA7 /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1E33A96D22B2E3DB003C5AA7 /* MainInterface.storyboard */; }; + 1E33A97322B2E3DB003C5AA7 /* NotificationExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 1E33A96422B2E3DB003C5AA7 /* NotificationExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + 1E33A97922B2EA78003C5AA7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1E33A97822B2EA78003C5AA7 /* Assets.xcassets */; }; 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 */; }; @@ -14,7 +21,39 @@ AA6671D322B1293000824252 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = AA6671D122B1293000824252 /* LaunchScreen.storyboard */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + 1E33A97122B2E3DB003C5AA7 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = AA6671BD22B1292D00824252 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 1E33A96322B2E3DB003C5AA7; + remoteInfo = NotificationExtension; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 1E33A97722B2E3DB003C5AA7 /* Embed App Extensions */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 13; + files = ( + 1E33A97322B2E3DB003C5AA7 /* NotificationExtension.appex in Embed App Extensions */, + ); + name = "Embed App Extensions"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ + 1E33A95E22B2C221003C5AA7 /* ChallengesTVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChallengesTVC.swift; sourceTree = ""; }; + 1E33A96422B2E3DB003C5AA7 /* NotificationExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = NotificationExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; + 1E33A96622B2E3DB003C5AA7 /* UserNotifications.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotifications.framework; path = System/Library/Frameworks/UserNotifications.framework; sourceTree = SDKROOT; }; + 1E33A96822B2E3DB003C5AA7 /* UserNotificationsUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotificationsUI.framework; path = System/Library/Frameworks/UserNotificationsUI.framework; sourceTree = SDKROOT; }; + 1E33A96B22B2E3DB003C5AA7 /* NotificationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationViewController.swift; sourceTree = ""; }; + 1E33A96E22B2E3DB003C5AA7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/MainInterface.storyboard; sourceTree = ""; }; + 1E33A97022B2E3DB003C5AA7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 1E33A97822B2EA78003C5AA7 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = SOURCE_ROOT; }; 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 = ""; }; AA6671CA22B1292D00824252 /* BaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = ""; }; @@ -25,6 +64,15 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 1E33A96122B2E3DB003C5AA7 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 1E33A96922B2E3DB003C5AA7 /* UserNotificationsUI.framework in Frameworks */, + 1E33A96722B2E3DB003C5AA7 /* UserNotifications.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; AA6671C222B1292D00824252 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -35,10 +83,32 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 1E33A96522B2E3DB003C5AA7 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 1E33A96622B2E3DB003C5AA7 /* UserNotifications.framework */, + 1E33A96822B2E3DB003C5AA7 /* UserNotificationsUI.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + 1E33A96A22B2E3DB003C5AA7 /* NotificationExtension */ = { + isa = PBXGroup; + children = ( + 1E33A97822B2EA78003C5AA7 /* Assets.xcassets */, + 1E33A96B22B2E3DB003C5AA7 /* NotificationViewController.swift */, + 1E33A96D22B2E3DB003C5AA7 /* MainInterface.storyboard */, + 1E33A97022B2E3DB003C5AA7 /* Info.plist */, + ); + path = NotificationExtension; + sourceTree = ""; + }; AA6671BC22B1292D00824252 = { isa = PBXGroup; children = ( AA6671C722B1292D00824252 /* LocalNotificationBase */, + 1E33A96A22B2E3DB003C5AA7 /* NotificationExtension */, + 1E33A96522B2E3DB003C5AA7 /* Frameworks */, AA6671C622B1292D00824252 /* Products */, ); sourceTree = ""; @@ -47,6 +117,7 @@ isa = PBXGroup; children = ( AA6671C522B1292D00824252 /* LocalNotificationBase.app */, + 1E33A96422B2E3DB003C5AA7 /* NotificationExtension.appex */, ); name = Products; sourceTree = ""; @@ -57,6 +128,7 @@ AA6671C822B1292D00824252 /* AppDelegate.swift */, AA6671CA22B1292D00824252 /* BaseViewController.swift */, AA6671CC22B1292D00824252 /* Main.storyboard */, + 1E33A95E22B2C221003C5AA7 /* ChallengesTVC.swift */, AA6671CF22B1293000824252 /* Assets.xcassets */, AA6671D122B1293000824252 /* LaunchScreen.storyboard */, AA6671D422B1293000824252 /* Info.plist */, @@ -67,6 +139,23 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ + 1E33A96322B2E3DB003C5AA7 /* NotificationExtension */ = { + isa = PBXNativeTarget; + buildConfigurationList = 1E33A97422B2E3DB003C5AA7 /* Build configuration list for PBXNativeTarget "NotificationExtension" */; + buildPhases = ( + 1E33A96022B2E3DB003C5AA7 /* Sources */, + 1E33A96122B2E3DB003C5AA7 /* Frameworks */, + 1E33A96222B2E3DB003C5AA7 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = NotificationExtension; + productName = NotificationExtension; + productReference = 1E33A96422B2E3DB003C5AA7 /* NotificationExtension.appex */; + productType = "com.apple.product-type.app-extension"; + }; AA6671C422B1292D00824252 /* LocalNotificationBase */ = { isa = PBXNativeTarget; buildConfigurationList = AA6671D722B1293000824252 /* Build configuration list for PBXNativeTarget "LocalNotificationBase" */; @@ -74,10 +163,12 @@ AA6671C122B1292D00824252 /* Sources */, AA6671C222B1292D00824252 /* Frameworks */, AA6671C322B1292D00824252 /* Resources */, + 1E33A97722B2E3DB003C5AA7 /* Embed App Extensions */, ); buildRules = ( ); dependencies = ( + 1E33A97222B2E3DB003C5AA7 /* PBXTargetDependency */, ); name = LocalNotificationBase; productName = LocalNotificationBase; @@ -94,6 +185,9 @@ LastUpgradeCheck = 1020; ORGANIZATIONNAME = "Bruno Omella Mainieri"; TargetAttributes = { + 1E33A96322B2E3DB003C5AA7 = { + CreatedOnToolsVersion = 10.2.1; + }; AA6671C422B1292D00824252 = { CreatedOnToolsVersion = 10.2.1; }; @@ -113,11 +207,21 @@ projectRoot = ""; targets = ( AA6671C422B1292D00824252 /* LocalNotificationBase */, + 1E33A96322B2E3DB003C5AA7 /* NotificationExtension */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + 1E33A96222B2E3DB003C5AA7 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 1E33A97922B2EA78003C5AA7 /* Assets.xcassets in Resources */, + 1E33A96F22B2E3DB003C5AA7 /* MainInterface.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; AA6671C322B1292D00824252 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -131,10 +235,19 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 1E33A96022B2E3DB003C5AA7 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 1E33A96C22B2E3DB003C5AA7 /* NotificationViewController.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; AA6671C122B1292D00824252 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 1E33A95F22B2C221003C5AA7 /* ChallengesTVC.swift in Sources */, AA6671CB22B1292D00824252 /* BaseViewController.swift in Sources */, AA6671C922B1292D00824252 /* AppDelegate.swift in Sources */, ); @@ -142,7 +255,23 @@ }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXTargetDependency section */ + 1E33A97222B2E3DB003C5AA7 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 1E33A96322B2E3DB003C5AA7 /* NotificationExtension */; + targetProxy = 1E33A97122B2E3DB003C5AA7 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + /* Begin PBXVariantGroup section */ + 1E33A96D22B2E3DB003C5AA7 /* MainInterface.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 1E33A96E22B2E3DB003C5AA7 /* Base */, + ); + name = MainInterface.storyboard; + sourceTree = ""; + }; AA6671CC22B1292D00824252 /* Main.storyboard */ = { isa = PBXVariantGroup; children = ( @@ -162,6 +291,44 @@ /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ + 1E33A97522B2E3DB003C5AA7 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = X54K5PJVGU; + INFOPLIST_FILE = NotificationExtension/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@executable_path/../../Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = br.com.mackmobile.LocalNotificationBase.NotificationExtension; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 1E33A97622B2E3DB003C5AA7 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = X54K5PJVGU; + INFOPLIST_FILE = NotificationExtension/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@executable_path/../../Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = br.com.mackmobile.LocalNotificationBase.NotificationExtension; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; AA6671D522B1293000824252 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -281,9 +448,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 = X54K5PJVGU; INFOPLIST_FILE = LocalNotificationBase/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -299,9 +467,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 = X54K5PJVGU; INFOPLIST_FILE = LocalNotificationBase/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -317,6 +486,15 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + 1E33A97422B2E3DB003C5AA7 /* Build configuration list for PBXNativeTarget "NotificationExtension" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1E33A97522B2E3DB003C5AA7 /* Debug */, + 1E33A97622B2E3DB003C5AA7 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; AA6671C022B1292D00824252 /* Build configuration list for PBXProject "LocalNotificationBase" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/LocalNotificationBase/AppDelegate.swift b/LocalNotificationBase/AppDelegate.swift index 07da379..ad34ac9 100644 --- a/LocalNotificationBase/AppDelegate.swift +++ b/LocalNotificationBase/AppDelegate.swift @@ -44,6 +44,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/Base.lproj/Main.storyboard b/LocalNotificationBase/Base.lproj/Main.storyboard index 0d2afb5..8312c96 100644 --- a/LocalNotificationBase/Base.lproj/Main.storyboard +++ b/LocalNotificationBase/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -10,7 +10,7 @@ - + @@ -18,9 +18,8 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LocalNotificationBase/ChallengesTVC.swift b/LocalNotificationBase/ChallengesTVC.swift new file mode 100644 index 0000000..b2b97f7 --- /dev/null +++ b/LocalNotificationBase/ChallengesTVC.swift @@ -0,0 +1,140 @@ +// +// ChallengesTVC.swift +// LocalNotificationBase +// +// Created by Paula Leite on 13/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import UIKit +import UserNotifications + +class ChallengesTVC: UITableViewController, UIPickerViewDelegate, UIPickerViewDataSource, UNUserNotificationCenterDelegate { + + @IBOutlet weak var titleTextField: UITextField! + + @IBOutlet weak var bodyTextField: UITextField! + + @IBOutlet weak var soundSwitch: UISwitch! + + @IBOutlet weak var badgeSwitch: UISwitch! + + @IBOutlet weak var timePicker: UIPickerView! + + var timeIntervals = [TimeInterval]() + + var selectedPickerIndex: Int = 0 + + override func viewDidLoad() { + super.viewDidLoad() + + tableView.tableFooterView = UIView(frame: CGRect.zero) + self.tableView.delegate = self + self.tableView.dataSource = self + let tap = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)) + self.view.addGestureRecognizer(tap) + tap.cancelsTouchesInView = false + + tableView.delaysContentTouches = false + + timeIntervals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + + self.timePicker.delegate = self + self.timePicker.dataSource = self + } + + func numberOfComponents(in pickerView: UIPickerView) -> Int { + return 1 + } + + // Adicionada para funcionar com Table View + func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { + return timeIntervals.count + } + + func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { + return "\(Int(timeIntervals[row]))" + } + + func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { + selectedPickerIndex = row + } + + @objc func dismissKeyboard() { + self.view.endEditing(true) + } + + @IBAction func setNotificationButton(_ sender: Any) { + + guard let title = titleTextField.text else { + return + } + + guard let body = bodyTextField.text else { + return + } + + let soundIsOn = soundSwitch.isOn + let badgeIsOn = badgeSwitch.isOn + + let notificationCenter = UNUserNotificationCenter.current() + + let repeatNotification = UNNotificationAction(identifier: "repeat", title: "Repeat", options: []) + + let doDefinedAction = UNNotificationAction(identifier: "doAction", title: "All done!", options: [.foreground]) + + // This is what iOS needs so he can make the actions + let calledCategory = UNNotificationCategory(identifier: "calledCategory", actions: [repeatNotification, doDefinedAction], intentIdentifiers: [], options: .customDismissAction) + + notificationCenter.setNotificationCategories([calledCategory]) + notificationCenter.delegate = self + + 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) + if soundIsOn { + content.sound = UNNotificationSound.default + } + + if badgeIsOn { + content.badge = 1 + } + + // This is how you make the category show up + content.categoryIdentifier = "calledCategory" + + let trigger = UNTimeIntervalNotificationTrigger(timeInterval: self.timeIntervals[self.selectedPickerIndex], repeats: false) + + let request = UNNotificationRequest(identifier: "notificationTest", 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") + } + + } + + } + + func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { + + UIApplication.shared.applicationIconBadgeNumber = 0 + + if response.actionIdentifier == "repeat" { + center.add(response.notification.request, withCompletionHandler: nil) + } else if response.actionIdentifier == "doAction" { + performSegue(withIdentifier: "textSegue", sender: self) + } + } + + +} diff --git a/NotificationExtension/Base.lproj/MainInterface.storyboard b/NotificationExtension/Base.lproj/MainInterface.storyboard new file mode 100644 index 0000000..96967f3 --- /dev/null +++ b/NotificationExtension/Base.lproj/MainInterface.storyboard @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/NotificationExtension/Info.plist b/NotificationExtension/Info.plist new file mode 100644 index 0000000..d154b70 --- /dev/null +++ b/NotificationExtension/Info.plist @@ -0,0 +1,42 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + NotificationExtension + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + XPC! + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + NSExtension + + NSExtensionAttributes + + UNNotificationExtensionDefaultContentHidden + + UNNotificationExtensionCategory + + calledCategory + + UNNotificationExtensionInitialContentSizeRatio + 0 + + NSExtensionMainStoryboard + MainInterface + NSExtensionPointIdentifier + com.apple.usernotifications.content-extension + + + diff --git a/NotificationExtension/NotificationViewController.swift b/NotificationExtension/NotificationViewController.swift new file mode 100644 index 0000000..ef67b0d --- /dev/null +++ b/NotificationExtension/NotificationViewController.swift @@ -0,0 +1,28 @@ +// +// NotificationViewController.swift +// NotificationExtension +// +// Created by Paula Leite on 13/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import UIKit +import UserNotifications +import UserNotificationsUI + +class NotificationViewController: UIViewController, UNNotificationContentExtension { + + + @IBOutlet var imageNotification: UIImageView! + @IBOutlet 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 + } + +}