got notifications good to go

and updated podfile
parent a3235b5f
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="M4Y-Lb-cyx">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="M4Y-Lb-cyx">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
......@@ -9,23 +13,24 @@
<!--Notification View Controller-->
<scene sceneID="cwh-vc-ff4">
<objects>
<viewController id="M4Y-Lb-cyx" userLabel="Notification View Controller" customClass="NotificationViewController" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="M4Y-Lb-cyx" userLabel="Notification View Controller" customClass="NotificationViewController" customModule="AlertNotificationExtention" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" simulatedAppContext="notificationCenter" id="S3S-Oj-5AN">
<rect key="frame" x="0.0" y="0.0" width="320" height="37"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="top" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Hello World" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="280" translatesAutoresizingMaskIntoConstraints="NO" id="GcN-lo-r42">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="1mD-z3-WYh">
<rect key="frame" x="0.0" y="0.0" width="320" height="37"/>
<connections>
<segue destination="9W9-6Q-a2K" kind="embed" id="XVL-2A-S2F"/>
</connections>
</containerView>
</subviews>
<color key="backgroundColor" red="0.45882353186607361" green="0.74901962280273438" blue="0.66666668653488159" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="2BE-c3-nQJ" firstAttribute="bottom" secondItem="GcN-lo-r42" secondAttribute="bottom" constant="8" symbolic="YES" id="0Q0-KW-PJ6"/>
<constraint firstItem="GcN-lo-r42" firstAttribute="leading" secondItem="2BE-c3-nQJ" secondAttribute="leading" constant="20" symbolic="YES" id="6Vq-gs-PHe"/>
<constraint firstItem="2BE-c3-nQJ" firstAttribute="trailing" secondItem="GcN-lo-r42" secondAttribute="trailing" constant="20" symbolic="YES" id="L8K-9R-egU"/>
<constraint firstItem="GcN-lo-r42" firstAttribute="top" secondItem="2BE-c3-nQJ" secondAttribute="top" constant="8" symbolic="YES" id="mYS-Cv-VNx"/>
<constraint firstItem="1mD-z3-WYh" firstAttribute="height" secondItem="S3S-Oj-5AN" secondAttribute="height" id="Dmj-pC-GXQ"/>
<constraint firstItem="1mD-z3-WYh" firstAttribute="centerX" secondItem="2BE-c3-nQJ" secondAttribute="centerX" id="SNc-7e-O8z"/>
<constraint firstItem="1mD-z3-WYh" firstAttribute="centerY" secondItem="2BE-c3-nQJ" secondAttribute="centerY" id="dul-Ck-Oww"/>
<constraint firstItem="1mD-z3-WYh" firstAttribute="width" secondItem="S3S-Oj-5AN" secondAttribute="width" id="r24-qT-usG"/>
</constraints>
<viewLayoutGuide key="safeArea" id="2BE-c3-nQJ"/>
</view>
......@@ -33,11 +38,26 @@
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<size key="freeformSize" width="320" height="37"/>
<connections>
<outlet property="label" destination="GcN-lo-r42" id="lpW-cU-7IG"/>
<outlet property="containerView" destination="1mD-z3-WYh" id="FhD-cv-isU"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="vXp-U4-Rya" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="41.600000000000001" y="25.637181409295355"/>
</scene>
<!--View Controller-->
<scene sceneID="8Dg-Dp-Wr9">
<objects>
<viewController id="9W9-6Q-a2K" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="iRA-Nc-NVT">
<rect key="frame" x="0.0" y="0.0" width="320" height="37"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="yGU-sF-ZdX" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="42" y="200"/>
</scene>
</scenes>
</document>
......@@ -25,9 +25,11 @@
<key>NSExtensionAttributes</key>
<dict>
<key>UNNotificationExtensionCategory</key>
<string>myNotificationCategory</string>
<string>alertNotify</string>
<key>UNNotificationExtensionInitialContentSizeRatio</key>
<real>1</real>
<integer>1</integer>
<key>UNNotificationExtensionDefaultContentHidden</key>
<true/>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
......
......@@ -10,17 +10,75 @@ import UIKit
import UserNotifications
import UserNotificationsUI
import RealmSwift
import WhatsOpenKit
class NotificationViewController: UIViewController, UNNotificationContentExtension {
@IBOutlet var label: UILabel?
override func viewDidLoad() {
@IBOutlet var containerView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any required interface initialization here.
}
func didReceive(_ notification: UNNotification) {
self.label?.text = notification.request.content.body
let realm = try! Realm(configuration: WOPDatabaseController.getConfig())
let results = realm.objects(WOPFacilitiesModel.self)
if results.count > 0 {
let model = results[0]
let alerts = model.alerts
let objs = alerts.filter(NSPredicate(format: "id = \((notification.request.content.userInfo["alertID"])!)"))
if objs.count > 0 {
let alert = objs.first
let storyboard = UIStoryboard(name: "WOPSharedUI", bundle: Bundle(for: WOPAlertDetailViewController.self))
let detailVC = storyboard.instantiateViewController(withIdentifier: "detailView") as! WOPAlertDetailViewController
detailVC.alert = alert
self.addChild(detailVC)
self.addSubview(detailVC.view, toView: containerView)
//attachChild(detailVC)
} else {
return
}
} else {
return
}
}
func addSubview(_ subView: UIView, toView parentView: UIView) {
parentView.addSubview(subView)
var viewBindingsDict = [String: AnyObject]()
viewBindingsDict["subView"] = subView
parentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[subView]|",
options: [], metrics: nil, views: viewBindingsDict))
parentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[subView]|",
options: [], metrics: nil, views: viewBindingsDict))
}
// Taken from Apple's SoupChef sample code
private func attachChild(_ viewController: UIViewController) {
addChild(viewController)
if let subview = viewController.view {
view.addSubview(subview)
subview.translatesAutoresizingMaskIntoConstraints = false
// Set the child controller's view to be the exact same size as the parent controller's view.
subview.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
subview.heightAnchor.constraint(equalTo: view.heightAnchor).isActive = true
subview.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
subview.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
}
viewController.didMove(toParent: self)
}
}
......@@ -47,6 +47,10 @@ target 'ShortcutsExtensionUI' do
important_pods
end
target 'AlertNotificationExtention' do
important_pods
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
......
......@@ -40,6 +40,6 @@ SPEC CHECKSUMS:
Realm: 50071da38fe079e0735e47c9f2eae738c68c5996
RealmSwift: 8a1e6a02b7a08cd17a31e3115143fb69fe5f3fb9
PODFILE CHECKSUM: c2fa08440be1a2902ec4a3ed351464719891fc3a
PODFILE CHECKSUM: 0589552d0fa556d4bb7ac2395184d9884a95f850
COCOAPODS: 1.6.0.beta.2
......@@ -40,6 +40,6 @@ SPEC CHECKSUMS:
Realm: 50071da38fe079e0735e47c9f2eae738c68c5996
RealmSwift: 8a1e6a02b7a08cd17a31e3115143fb69fe5f3fb9
PODFILE CHECKSUM: c2fa08440be1a2902ec4a3ed351464719891fc3a
PODFILE CHECKSUM: 0589552d0fa556d4bb7ac2395184d9884a95f850
COCOAPODS: 1.6.0.beta.2
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -5,6 +5,7 @@
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
<string>arm64</string>
</array>
</dict>
</plist>
......@@ -26,6 +26,7 @@
<array>
<string>arm64</string>
<string>arm64</string>
<string>arm64</string>
</array>
</dict>
</plist>
......@@ -5,6 +5,7 @@
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
<string>arm64</string>
</array>
</dict>
</plist>
......@@ -26,6 +26,7 @@
<array>
<string>arm64</string>
<string>arm64</string>
<string>arm64</string>
</array>
</dict>
</plist>
......@@ -26,6 +26,7 @@
<array>
<string>arm64</string>
<string>arm64</string>
<string>arm64</string>
</array>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>${PRODUCT_BUNDLE_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>${CURRENT_PROJECT_VERSION}</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
#import <Foundation/Foundation.h>
@interface PodsDummy_Pods_AlertNotificationExtention : NSObject
@end
@implementation PodsDummy_Pods_AlertNotificationExtention
@end
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#else
#ifndef FOUNDATION_EXPORT
#if defined(__cplusplus)
#define FOUNDATION_EXPORT extern "C"
#else
#define FOUNDATION_EXPORT extern
#endif
#endif
#endif
FOUNDATION_EXPORT double Pods_AlertNotificationExtentionVersionNumber;
FOUNDATION_EXPORT const unsigned char Pods_AlertNotificationExtentionVersionString[];
FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/ObjectMapper" "${PODS_CONFIGURATION_BUILD_DIR}/ObjectMapper+Realm" "${PODS_CONFIGURATION_BUILD_DIR}/Realm" "${PODS_CONFIGURATION_BUILD_DIR}/RealmSwift"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/ObjectMapper+Realm/ObjectMapper_Realm.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/ObjectMapper/ObjectMapper.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/Realm/Realm.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/RealmSwift/RealmSwift.framework/Headers"
LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' '@executable_path/../../Frameworks'
LIBRARY_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Realm/core"
OTHER_LDFLAGS = $(inherited) -ObjC -l"c++" -l"realmcore-ios" -l"z" -framework "ObjectMapper" -framework "ObjectMapper_Realm" -framework "Realm" -framework "RealmSwift" -framework "Security"
OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS
PODS_BUILD_DIR = ${BUILD_DIR}
PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
PODS_PODFILE_DIR_PATH = ${SRCROOT}/.
PODS_ROOT = ${SRCROOT}/Pods
FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/ObjectMapper" "${PODS_CONFIGURATION_BUILD_DIR}/ObjectMapper+Realm" "${PODS_CONFIGURATION_BUILD_DIR}/Realm" "${PODS_CONFIGURATION_BUILD_DIR}/RealmSwift"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/ObjectMapper+Realm/ObjectMapper_Realm.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/ObjectMapper/ObjectMapper.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/Realm/Realm.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/RealmSwift/RealmSwift.framework/Headers"
LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' '@executable_path/../../Frameworks'
LIBRARY_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Realm/core"
OTHER_LDFLAGS = $(inherited) -ObjC -l"c++" -l"realmcore-ios" -l"z" -framework "ObjectMapper" -framework "ObjectMapper_Realm" -framework "Realm" -framework "RealmSwift" -framework "Security"
OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS
PODS_BUILD_DIR = ${BUILD_DIR}
PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
PODS_PODFILE_DIR_PATH = ${SRCROOT}/.
PODS_ROOT = ${SRCROOT}/Pods
framework module Pods_AlertNotificationExtention {
umbrella header "Pods-AlertNotificationExtention-umbrella.h"
export *
module * { export * }
}
FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/ObjectMapper" "${PODS_CONFIGURATION_BUILD_DIR}/ObjectMapper+Realm" "${PODS_CONFIGURATION_BUILD_DIR}/Realm" "${PODS_CONFIGURATION_BUILD_DIR}/RealmSwift"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/ObjectMapper+Realm/ObjectMapper_Realm.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/ObjectMapper/ObjectMapper.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/Realm/Realm.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/RealmSwift/RealmSwift.framework/Headers"
LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' '@executable_path/../../Frameworks'
LIBRARY_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Realm/core"
OTHER_LDFLAGS = $(inherited) -ObjC -l"c++" -l"realmcore-ios" -l"z" -framework "ObjectMapper" -framework "ObjectMapper_Realm" -framework "Realm" -framework "RealmSwift" -framework "Security"
OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS
PODS_BUILD_DIR = ${BUILD_DIR}
PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
PODS_PODFILE_DIR_PATH = ${SRCROOT}/.
PODS_ROOT = ${SRCROOT}/Pods
......@@ -26,6 +26,7 @@
<array>
<string>arm64</string>
<string>arm64</string>
<string>arm64</string>
</array>
</dict>
</plist>
......@@ -26,6 +26,7 @@
<array>
<string>arm64</string>
<string>arm64</string>
<string>arm64</string>
</array>
</dict>
</plist>
......@@ -26,6 +26,7 @@
<array>
<string>arm64</string>
<string>arm64</string>
<string>arm64</string>
</array>
</dict>
</plist>
......@@ -26,6 +26,7 @@
<array>
<string>arm64</string>
<string>arm64</string>
<string>arm64</string>
</array>
</dict>
</plist>
......@@ -26,6 +26,7 @@
<array>
<string>arm64</string>
<string>arm64</string>
<string>arm64</string>
</array>
</dict>
</plist>
......@@ -26,6 +26,7 @@
<array>
<string>arm64</string>
<string>arm64</string>
<string>arm64</string>
</array>
</dict>
</plist>
......@@ -26,6 +26,7 @@
<array>
<string>arm64</string>
<string>arm64</string>
<string>arm64</string>
</array>
</dict>
</plist>
......@@ -26,6 +26,7 @@
<array>
<string>arm64</string>
<string>arm64</string>
<string>arm64</string>
</array>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0920"
version = "2.0">
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
......@@ -50,8 +50,7 @@
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
launchAutomaticallySubstyle = "1">
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
......
......@@ -44,7 +44,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
application.setMinimumBackgroundFetchInterval(3600)
UNUserNotificationCenter.current().delegate = self
let alertNotificationCategory = UNNotificationCategory(identifier: "alertNotify", actions: [], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: "Alert", options: .hiddenPreviewsShowTitle)
let nc = UNUserNotificationCenter.current()
nc.delegate = self
nc.setNotificationCategories([alertNotificationCategory])
nc.getNotificationSettings { (settings) in
if settings.authorizationStatus == .notDetermined {
nc.requestAuthorization(options: [.badge, .sound, .alert, .providesAppNotificationSettings, .provisional], completionHandler: { (authorized, error) in
return // it's a provisonal request nbd
})
}
}
return true
}
......@@ -114,15 +125,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
if notifications == nil {
var setAlerts = [String: Bool]()
setAlerts.updateValue(false, forKey: "informational")
setAlerts.updateValue(false, forKey: "minor alerts")
setAlerts.updateValue(false, forKey: "major alerts")
setAlerts.updateValue(false, forKey: "emergency")
setAlerts.updateValue(true, forKey: "minor alerts")
setAlerts.updateValue(true, forKey: "major alerts")
setAlerts.updateValue(true, forKey: "emergency")
defaults.set(setAlerts, forKey: "notificationDefaults")
}
let alertIDs = defaults.dictionary(forKey: "alertIDNotified")
if notifications == nil {
var setAlerts = [String: Bool]()
if alertIDs == nil {
let setAlerts = [String: Bool]()
defaults.set(setAlerts, forKey: "alertIDNotified")
}
......@@ -199,7 +210,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.getNotificationSettings { (settings) in
// Do not schedule notifications if not authorized.
guard settings.authorizationStatus == .authorized else {return}
guard settings.authorizationStatus == .authorized || settings.authorizationStatus == .provisional else {return}
let defaults = WOPDatabaseController.getDefaults()
let inAppSettings = defaults.dictionary(forKey: "notificationDefaults") as! [String: Bool]
......@@ -240,6 +251,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func singleNotification(_ alert: WOPAlert, nc: UNUserNotificationCenter, ids: [String: Bool], defaults: UserDefaults) {
if ids["\(alert.id)"] == nil {
let content = UNMutableNotificationContent()
content.categoryIdentifier = "alertNotify"
switch alert.urgency {
case "info":
content.title = "Information"
......@@ -252,7 +264,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
default:
content.title = "Alert"
}
content.body = alert.message
if alert.message != "" {
content.body = alert.message
} else {
content.subtitle = alert.subject
content.body = alert.body
}
content.badge = 1 as NSNumber
let sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: "patriots.caf"))
content.sound = sound
......@@ -285,5 +303,6 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, openSettingsFor notification: UNNotification?) {
NotificationCenter.default.post(Notification(name: Notification.Name(rawValue: "launchToNotificationSettings"), object: notification, userInfo: nil))
}
}
......@@ -10,6 +10,7 @@ import UIKit
import SafariServices
import MessageUI
import StoreKit
import UserNotifications
import WhatsOpenKit
class SettingsTableViewController: UITableViewController, MFMailComposeViewControllerDelegate {
......@@ -207,7 +208,27 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
present(mailvc, animated: true)
}
} else if settingcell.textLabel?.text == "Alert Notifications" {
toNotifications(nil)
let nc = UNUserNotificationCenter.current()
nc.requestAuthorization(options: [.badge, .sound, .alert, .providesAppNotificationSettings]) { (authorized, error) in
if authorized {
DispatchQueue.main.async {
self.toNotifications(nil)
}
} else {
let alert = UIAlertController(title: "Notifications Are Disabled", message: "You can manage your preferred notification options inside Settings", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Configure in Settings", style: .default, handler: { (action) in
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, completionHandler: nil)
alert.dismiss(animated: true, completion: nil)
}))
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action) in
alert.dismiss(animated: true, completion: nil)
}))
DispatchQueue.main.async {
self.present(alert, animated: true, completion: nil)
}
}
}
}
else if settingcell.textLabel?.text == "Select App Icon" {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "setAppIcon")
......
......@@ -480,58 +480,12 @@ public class WOPUtilities: NSObject {
*/
public static func setAlertNotificationDefaults(_ key: String, value: Bool) -> Bool {
var returning = false
if value == true {
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.getNotificationSettings { (settings) in
if settings.authorizationStatus == .notDetermined {
notificationCenter.requestAuthorization(options: [.alert, .sound, .badge], completionHandler: {state, error in
if state == true {
let defaults = WOPDatabaseController.getDefaults()
var alerts = defaults.dictionary(forKey: "notificationDefaults") as! [String: Bool]?
if alerts != nil {
alerts!.updateValue(value, forKey: key)
defaults.set(alerts, forKey: "notificationDefaults")
returning = true
return
}
else {
returning = false
return
}
} else {
return
}
})
} else {
// Do not schedule notifications if not authorized.
guard settings.authorizationStatus == .authorized else {return}
let defaults = WOPDatabaseController.getDefaults()
var alerts = defaults.dictionary(forKey: "notificationDefaults") as! [String: Bool]?
if alerts != nil {
alerts!.updateValue(value, forKey: key)
defaults.set(alerts, forKey: "notificationDefaults")