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/Background.imageset/Background.jpg b/Assets.xcassets/Background.imageset/Background.jpg new file mode 100644 index 0000000..1787d57 Binary files /dev/null and b/Assets.xcassets/Background.imageset/Background.jpg differ diff --git a/Assets.xcassets/Background.imageset/Contents.json b/Assets.xcassets/Background.imageset/Contents.json new file mode 100644 index 0000000..73788cc --- /dev/null +++ b/Assets.xcassets/Background.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "Background.jpg", + "scale" : "3x" + } + ], + "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/LocalNotificationBase.xcodeproj/project.pbxproj b/LocalNotificationBase.xcodeproj/project.pbxproj index dd7afac..4089272 100644 --- a/LocalNotificationBase.xcodeproj/project.pbxproj +++ b/LocalNotificationBase.xcodeproj/project.pbxproj @@ -12,8 +12,39 @@ 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 */; }; + B663A21822B2E3D900EEAA55 /* UserNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B663A21722B2E3D900EEAA55 /* UserNotifications.framework */; }; + B663A21A22B2E3D900EEAA55 /* UserNotificationsUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B663A21922B2E3D900EEAA55 /* UserNotificationsUI.framework */; }; + B663A21D22B2E3D900EEAA55 /* NotificationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B663A21C22B2E3D900EEAA55 /* NotificationViewController.swift */; }; + B663A22022B2E3D900EEAA55 /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B663A21E22B2E3D900EEAA55 /* MainInterface.storyboard */; }; + B663A22422B2E3D900EEAA55 /* NotificationExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = B663A21522B2E3D900EEAA55 /* NotificationExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + B6B7047422B2C1F70094631F /* ChallengesTableVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6B7047322B2C1F70094631F /* ChallengesTableVC.swift */; }; + B6F52D7D22B2EAD6008BFB11 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B6F52D7C22B2EAD6008BFB11 /* Assets.xcassets */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + B663A22222B2E3D900EEAA55 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = AA6671BD22B1292D00824252 /* Project object */; + proxyType = 1; + remoteGlobalIDString = B663A21422B2E3D900EEAA55; + remoteInfo = NotificationExtension; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + B663A22822B2E3D900EEAA55 /* Embed App Extensions */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 13; + files = ( + B663A22422B2E3D900EEAA55 /* NotificationExtension.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 +53,14 @@ 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 = ""; }; + B663A21522B2E3D900EEAA55 /* NotificationExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = NotificationExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; + B663A21722B2E3D900EEAA55 /* UserNotifications.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotifications.framework; path = System/Library/Frameworks/UserNotifications.framework; sourceTree = SDKROOT; }; + B663A21922B2E3D900EEAA55 /* UserNotificationsUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotificationsUI.framework; path = System/Library/Frameworks/UserNotificationsUI.framework; sourceTree = SDKROOT; }; + B663A21C22B2E3D900EEAA55 /* NotificationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationViewController.swift; sourceTree = ""; }; + B663A21F22B2E3D900EEAA55 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/MainInterface.storyboard; sourceTree = ""; }; + B663A22122B2E3D900EEAA55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + B6B7047322B2C1F70094631F /* ChallengesTableVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChallengesTableVC.swift; sourceTree = ""; }; + B6F52D7C22B2EAD6008BFB11 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = SOURCE_ROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -32,6 +71,15 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + B663A21222B2E3D900EEAA55 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + B663A21A22B2E3D900EEAA55 /* UserNotificationsUI.framework in Frameworks */, + B663A21822B2E3D900EEAA55 /* UserNotifications.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -39,6 +87,8 @@ isa = PBXGroup; children = ( AA6671C722B1292D00824252 /* LocalNotificationBase */, + B663A21B22B2E3D900EEAA55 /* NotificationExtension */, + B663A21622B2E3D900EEAA55 /* Frameworks */, AA6671C622B1292D00824252 /* Products */, ); sourceTree = ""; @@ -47,6 +97,7 @@ isa = PBXGroup; children = ( AA6671C522B1292D00824252 /* LocalNotificationBase.app */, + B663A21522B2E3D900EEAA55 /* NotificationExtension.appex */, ); name = Products; sourceTree = ""; @@ -54,16 +105,53 @@ AA6671C722B1292D00824252 /* LocalNotificationBase */ = { isa = PBXGroup; children = ( + B6B7047622B2C2190094631F /* Storyboard */, + B6B7047522B2C2020094631F /* Controller */, AA6671C822B1292D00824252 /* AppDelegate.swift */, - AA6671CA22B1292D00824252 /* BaseViewController.swift */, - AA6671CC22B1292D00824252 /* Main.storyboard */, AA6671CF22B1293000824252 /* Assets.xcassets */, - AA6671D122B1293000824252 /* LaunchScreen.storyboard */, AA6671D422B1293000824252 /* Info.plist */, ); path = LocalNotificationBase; sourceTree = ""; }; + B663A21622B2E3D900EEAA55 /* Frameworks */ = { + isa = PBXGroup; + children = ( + B663A21722B2E3D900EEAA55 /* UserNotifications.framework */, + B663A21922B2E3D900EEAA55 /* UserNotificationsUI.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + B663A21B22B2E3D900EEAA55 /* NotificationExtension */ = { + isa = PBXGroup; + children = ( + B6F52D7C22B2EAD6008BFB11 /* Assets.xcassets */, + B663A21C22B2E3D900EEAA55 /* NotificationViewController.swift */, + B663A21E22B2E3D900EEAA55 /* MainInterface.storyboard */, + B663A22122B2E3D900EEAA55 /* Info.plist */, + ); + path = NotificationExtension; + sourceTree = ""; + }; + B6B7047522B2C2020094631F /* Controller */ = { + isa = PBXGroup; + children = ( + AA6671CA22B1292D00824252 /* BaseViewController.swift */, + B6B7047322B2C1F70094631F /* ChallengesTableVC.swift */, + ); + path = Controller; + sourceTree = ""; + }; + B6B7047622B2C2190094631F /* Storyboard */ = { + isa = PBXGroup; + children = ( + AA6671CC22B1292D00824252 /* Main.storyboard */, + AA6671D122B1293000824252 /* LaunchScreen.storyboard */, + ); + path = Storyboard; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -74,16 +162,35 @@ AA6671C122B1292D00824252 /* Sources */, AA6671C222B1292D00824252 /* Frameworks */, AA6671C322B1292D00824252 /* Resources */, + B663A22822B2E3D900EEAA55 /* Embed App Extensions */, ); buildRules = ( ); dependencies = ( + B663A22322B2E3D900EEAA55 /* PBXTargetDependency */, ); name = LocalNotificationBase; productName = LocalNotificationBase; productReference = AA6671C522B1292D00824252 /* LocalNotificationBase.app */; productType = "com.apple.product-type.application"; }; + B663A21422B2E3D900EEAA55 /* NotificationExtension */ = { + isa = PBXNativeTarget; + buildConfigurationList = B663A22722B2E3D900EEAA55 /* Build configuration list for PBXNativeTarget "NotificationExtension" */; + buildPhases = ( + B663A21122B2E3D900EEAA55 /* Sources */, + B663A21222B2E3D900EEAA55 /* Frameworks */, + B663A21322B2E3D900EEAA55 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = NotificationExtension; + productName = NotificationExtension; + productReference = B663A21522B2E3D900EEAA55 /* NotificationExtension.appex */; + productType = "com.apple.product-type.app-extension"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -97,6 +204,9 @@ AA6671C422B1292D00824252 = { CreatedOnToolsVersion = 10.2.1; }; + B663A21422B2E3D900EEAA55 = { + CreatedOnToolsVersion = 10.2.1; + }; }; }; buildConfigurationList = AA6671C022B1292D00824252 /* Build configuration list for PBXProject "LocalNotificationBase" */; @@ -113,6 +223,7 @@ projectRoot = ""; targets = ( AA6671C422B1292D00824252 /* LocalNotificationBase */, + B663A21422B2E3D900EEAA55 /* NotificationExtension */, ); }; /* End PBXProject section */ @@ -128,6 +239,15 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + B663A21322B2E3D900EEAA55 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + B6F52D7D22B2EAD6008BFB11 /* Assets.xcassets in Resources */, + B663A22022B2E3D900EEAA55 /* MainInterface.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -137,11 +257,28 @@ files = ( AA6671CB22B1292D00824252 /* BaseViewController.swift in Sources */, AA6671C922B1292D00824252 /* AppDelegate.swift in Sources */, + B6B7047422B2C1F70094631F /* ChallengesTableVC.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + B663A21122B2E3D900EEAA55 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + B663A21D22B2E3D900EEAA55 /* NotificationViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXTargetDependency section */ + B663A22322B2E3D900EEAA55 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = B663A21422B2E3D900EEAA55 /* NotificationExtension */; + targetProxy = B663A22222B2E3D900EEAA55 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + /* Begin PBXVariantGroup section */ AA6671CC22B1292D00824252 /* Main.storyboard */ = { isa = PBXVariantGroup; @@ -159,6 +296,14 @@ name = LaunchScreen.storyboard; sourceTree = ""; }; + B663A21E22B2E3D900EEAA55 /* MainInterface.storyboard */ = { + isa = PBXVariantGroup; + children = ( + B663A21F22B2E3D900EEAA55 /* Base */, + ); + name = MainInterface.storyboard; + sourceTree = ""; + }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ @@ -281,9 +426,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 = 87G2Y58K9U; INFOPLIST_FILE = LocalNotificationBase/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -299,9 +445,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 = 87G2Y58K9U; INFOPLIST_FILE = LocalNotificationBase/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -314,6 +461,44 @@ }; name = Release; }; + B663A22522B2E3D900EEAA55 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 87G2Y58K9U; + 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; + }; + B663A22622B2E3D900EEAA55 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 87G2Y58K9U; + 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; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -335,6 +520,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + B663A22722B2E3D900EEAA55 /* Build configuration list for PBXNativeTarget "NotificationExtension" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + B663A22522B2E3D900EEAA55 /* Debug */, + B663A22622B2E3D900EEAA55 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ }; rootObject = AA6671BD22B1292D00824252 /* Project object */; diff --git a/LocalNotificationBase.xcodeproj/xcshareddata/xcschemes/LocalNotificationBase.xcscheme b/LocalNotificationBase.xcodeproj/xcshareddata/xcschemes/LocalNotificationBase.xcscheme new file mode 100644 index 0000000..8056ecb --- /dev/null +++ b/LocalNotificationBase.xcodeproj/xcshareddata/xcschemes/LocalNotificationBase.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LocalNotificationBase/AppDelegate.swift b/LocalNotificationBase/AppDelegate.swift index 07da379..61157ab 100644 --- a/LocalNotificationBase/AppDelegate.swift +++ b/LocalNotificationBase/AppDelegate.swift @@ -14,10 +14,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. - let options: UNAuthorizationOptions = [.alert,.sound,.badge] + let options: UNAuthorizationOptions = [.alert, .sound, .badge] let notificationCenter = UNUserNotificationCenter.current() notificationCenter.requestAuthorization(options: options) { (didAllow, error) in @@ -44,12 +43,11 @@ 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) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } - - } diff --git a/LocalNotificationBase/Base.lproj/Main.storyboard b/LocalNotificationBase/Base.lproj/Main.storyboard deleted file mode 100644 index 0d2afb5..0000000 --- a/LocalNotificationBase/Base.lproj/Main.storyboard +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/LocalNotificationBase/BaseViewController.swift b/LocalNotificationBase/Controller/BaseViewController.swift similarity index 100% rename from LocalNotificationBase/BaseViewController.swift rename to LocalNotificationBase/Controller/BaseViewController.swift diff --git a/LocalNotificationBase/Controller/ChallengesTableVC.swift b/LocalNotificationBase/Controller/ChallengesTableVC.swift new file mode 100644 index 0000000..a32e708 --- /dev/null +++ b/LocalNotificationBase/Controller/ChallengesTableVC.swift @@ -0,0 +1,150 @@ +// +// ChallengesTableVC.swift +// LocalNotificationBase +// +// Created by Lucas Fernandez Nicolau on 13/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import UIKit +import UserNotifications + +enum Action: String { + case repeats = "repeats" + case performSegue = "performSegue" +} + +class ChallengesTableVC: UITableViewController, UITextFieldDelegate, UIPickerViewDelegate, UIPickerViewDataSource, UNUserNotificationCenterDelegate { + + @IBOutlet var titleTextField: UITextField! + @IBOutlet var bodyTextField: UITextField! + @IBOutlet var soundSwitch: UISwitch! + @IBOutlet var badgesSwitch: UISwitch! + @IBOutlet var timePickerView: UIPickerView! + + var timeIntervals = [Int]() + var selectedRow = 0 + + override func viewDidLoad() { + super.viewDidLoad() + + tableView.tableFooterView = UIView(frame: CGRect.zero) + tableView.delaysContentTouches = false + tableView.keyboardDismissMode = .interactive + + timePickerView.dataSource = self + timePickerView.delegate = self + + titleTextField.delegate = self + titleTextField.autocapitalizationType = .words + titleTextField.clearButtonMode = .whileEditing + titleTextField.returnKeyType = .done + + bodyTextField.delegate = self + bodyTextField.autocapitalizationType = .sentences + bodyTextField.clearButtonMode = .whileEditing + bodyTextField.returnKeyType = .done + + for i in 3 ... 20 { + timeIntervals.append(i) + } + + let tap = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)) + view.addGestureRecognizer(tap) + } + + @objc func dismissKeyboard() { + view.endEditing(true) + } + + func textFieldShouldReturn(_ textField: UITextField) -> Bool { + textField.resignFirstResponder() + return false + } + + func numberOfComponents(in pickerView: UIPickerView) -> Int { + return 1 + } + + func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { + return timeIntervals.count + } + + func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { + return "\(timeIntervals[row])" + } + + func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { + self.selectedRow = row + } + + @IBAction func buttonTapped(_ sender: UIButton) { + + guard let title = titleTextField.text, + titleTextField.text?.trimmingCharacters(in: .whitespacesAndNewlines) != "" else { return } + guard let body = bodyTextField.text, + bodyTextField.text?.trimmingCharacters(in: .whitespacesAndNewlines) != "" else { return } + + let timeInterval = TimeInterval(timeIntervals[selectedRow]) + setNotification(with: title, and: body, in: timeInterval, using: [soundSwitch.isOn, badgesSwitch.isOn]) + } + + func setNotification(with title: String, and body: String, in seconds: TimeInterval, using options: [Bool]) { + let notificationCenter = UNUserNotificationCenter.current() + notificationCenter.delegate = self + + let repeatAction = UNNotificationAction(identifier: Action.repeats.rawValue, + title: "Repeat", + options: []) + + let performSegueAction = UNNotificationAction(identifier: Action.performSegue.rawValue, + title: "Perform Segue", options: [.foreground]) + + let generalCategory = UNNotificationCategory(identifier: "generalCatID", + actions: [repeatAction, performSegueAction], + intentIdentifiers: [], + options: [.customDismissAction]) + + notificationCenter.setNotificationCategories([generalCategory]) + + 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 = options[0] ? UNNotificationSound.default : nil + content.badge = options[1] ? 1 : 0 + content.categoryIdentifier = "generalCatID" + + let trigger = UNTimeIntervalNotificationTrigger(timeInterval: seconds, repeats: false) + let request = UNNotificationRequest(identifier: "testNotification", content: content, trigger: trigger) + + notificationCenter.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 + + switch response.actionIdentifier { + case Action.repeats.rawValue: + center.add(response.notification.request, withCompletionHandler: nil) + case Action.performSegue.rawValue: + performSegue(withIdentifier: "secondScreenSegue", sender: self) + default: + return + } + + completionHandler() + } +} diff --git a/LocalNotificationBase/Base.lproj/LaunchScreen.storyboard b/LocalNotificationBase/Storyboard/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from LocalNotificationBase/Base.lproj/LaunchScreen.storyboard rename to LocalNotificationBase/Storyboard/Base.lproj/LaunchScreen.storyboard diff --git a/LocalNotificationBase/Storyboard/Base.lproj/Main.storyboard b/LocalNotificationBase/Storyboard/Base.lproj/Main.storyboard new file mode 100644 index 0000000..9500cdd --- /dev/null +++ b/LocalNotificationBase/Storyboard/Base.lproj/Main.storyboard @@ -0,0 +1,304 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/NotificationExtension/Base.lproj/MainInterface.storyboard b/NotificationExtension/Base.lproj/MainInterface.storyboard new file mode 100644 index 0000000..c163e70 --- /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..09841d3 --- /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 + + generalCatID + + UNNotificationExtensionInitialContentSizeRatio + 1 + + NSExtensionMainStoryboard + MainInterface + NSExtensionPointIdentifier + com.apple.usernotifications.content-extension + + + diff --git a/NotificationExtension/NotificationViewController.swift b/NotificationExtension/NotificationViewController.swift new file mode 100644 index 0000000..bef0cf9 --- /dev/null +++ b/NotificationExtension/NotificationViewController.swift @@ -0,0 +1,25 @@ +// +// NotificationViewController.swift +// NotificationExtension +// +// Created by Lucas Fernandez Nicolau on 13/06/19. +// Copyright © 2019 Bruno Omella Mainieri. All rights reserved. +// + +import UIKit +import UserNotifications +import UserNotificationsUI + +class NotificationViewController: UIViewController, UNNotificationContentExtension { + + @IBOutlet var label: UILabel? + @IBOutlet var bgImageView: UIImageView? + + override func viewDidLoad() { + super.viewDidLoad() + } + + func didReceive(_ notification: UNNotification) { + self.label?.text = notification.request.content.body + } +}