Notifications work as intended

now for the content extension
parent 8b591540
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0920"
version = "1.3">
version = "2.0">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
......@@ -50,7 +50,8 @@
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
allowLocationSimulation = "YES"
launchAutomaticallySubstyle = "1">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
......@@ -86,6 +87,7 @@
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "App Store"
customArchiveName = "What&apos;s Open"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
......@@ -20,7 +20,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func applicationDidBecomeActive(_ application: UIApplication) {
application.applicationIconBadgeNumber = 0
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
......@@ -162,6 +165,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let fromRealm = results[0]
try! realm.write {
fromRealm.facilities.removeAll()
fromRealm.alerts.removeAll()
for f in facilities! {
fromRealm.facilities.append(f)
}
......@@ -176,10 +180,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
/*
let a = WOPAlert(JSONString: "{\"id\": 20,\"created\": \"2018-11-30T12:00:28.109052-05:00\",\"modified\": \"2019-01-23T10:30:32.313528-05:00\",\"urgency_tag\": \"info\",\"message\": \"Mason is closed Mon, Jan 21. Some services are open. Dining Hours: https://dining.gmu.edu/wp-content/uploads/2019/01/MLK-HOO-1.png\",\"start_datetime\": \"2019-01-21T00:00:00-05:00\",\"end_datetime\": \"2019-01-21T23:59:00-05:00\"}")
alerts?.append(a!)*/
self.scheduleNotifications(for: alerts!)
completionHandler(UIBackgroundFetchResult.newData)
}
self.scheduleNotifications(for: alerts!)
} else {
completionHandler(UIBackgroundFetchResult.failed)
}
......@@ -203,9 +208,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let formatter = ISO8601DateFormatter()
formatter.timeZone = TimeZone(identifier: "America/New_York")
let now = Date()
dump(alerts)
for alert in alerts {
if now.isGreaterThanDate(dateToCompare: formatter.date(from: alert.startDate)!) && now.isLessThanDate(dateToCompare: formatter.date(from: alert.endDate)!) {
if true || (now.isGreaterThanDate(dateToCompare: formatter.date(from: alert.startDate)!) && now.isLessThanDate(dateToCompare: formatter.date(from: alert.endDate)!)) {
switch alert.urgency {
case "info":
if inAppSettings["informational"]! {
......@@ -228,6 +232,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}
}
}
}
......@@ -251,7 +256,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
content.badge = 1 as NSNumber
let sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: "patriots.caf"))
content.sound = sound
content.userInfo = ["alert": alert.id]
content.userInfo = ["alertID": alert.id]
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false))
nc.add(request, withCompletionHandler: {error in
......
......@@ -160,7 +160,8 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
self.presentDetailView(destination!, tapped: tapped)
}
else {
let destination = self.storyboard?.instantiateViewController(withIdentifier: "alertDetail") as? WOPAlertDetailViewController
let storyboard = UIStoryboard(name: "WOPSharedUI", bundle: Bundle(for: WOPAlertDetailViewController.self))
let destination = storyboard.instantiateViewController(withIdentifier: "alertDetail") as? WOPAlertDetailViewController
let tapped = self.LocationsList.cellForItem(at: indexPath!) as! AlertCollectionViewCell
destination?.alert = tapped.alert
self.presentDetailView(destination!, tapped: tapped)
......@@ -257,7 +258,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
@objc func toAlertFromNotification(_ notification: Notification) {
let notification = notification.object as? UNNotification
let alert = realm.objects(WOPFacilitiesModel.self)[0].alerts.filter(NSPredicate(format: "id = \" \((notification?.request.content.userInfo["alertID"])!) \"")).first
let alert = realm.objects(WOPFacilitiesModel.self)[0].alerts.filter(NSPredicate(format: "id = \((notification?.request.content.userInfo["alertID"])!)")).first
if(alert == nil) {
return // don't do anything
}
......@@ -826,7 +827,11 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
cell.imageView.image = #imageLiteral(resourceName: "major")
cell.imageView.accessibilityLabel = "Alert"
}
cell.messageLabel.text = currentAlerts[indexPath.row].message
if currentAlerts[indexPath.row].message != "" {
cell.messageLabel.text = currentAlerts[indexPath.row].message
} else {
cell.messageLabel.text = currentAlerts[indexPath.row].subject
}
return cell
}
......
......@@ -36,12 +36,21 @@ public class WOPAlertDetailViewController: UIViewController {
self.imageView.image = #imageLiteral(resourceName: "major")
self.nameLabel.text = "Alert"
}
self.messageView.text = alert.message
// Do any additional setup after loading the view.
if alert.message != "" { // API pre-2.2
self.messageView.text = alert.message
} else { // API 2.2+
let message = NSMutableAttributedString(string: alert.subject, attributes: [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .title1).bold()])
message.append(NSAttributedString(string: "\n\n"))
message.append(NSAttributedString(string: alert.body, attributes: [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .body)]))
message.append(NSAttributedString(string: "\n\n"))
message.append(NSAttributedString(string: alert.url, attributes: [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .subheadline).bold()]))
self.messageView.attributedText = message
}
// dynamic font sizes
self.nameLabel.font = UIFont.preferredFont(forTextStyle: .title1)
self.messageView.font = UIFont.preferredFont(forTextStyle: .body)
self.nameLabel.font = UIFont.preferredFont(forTextStyle: .title1).bold()
}
override public func didReceiveMemoryWarning() {
......@@ -61,4 +70,20 @@ public class WOPAlertDetailViewController: UIViewController {
*/
}
// https://spin.atomicobject.com/2018/02/02/swift-scaled-font-bold-italic/
extension UIFont {
func withTraits(traits:UIFontDescriptor.SymbolicTraits) -> UIFont {
let descriptor = fontDescriptor.withSymbolicTraits(traits)
return UIFont(descriptor: descriptor!, size: 0) //size 0 means keep the size as it is
}
func bold() -> UIFont {
return withTraits(traits: .traitBold)
}
func italic() -> UIFont {
return withTraits(traits: .traitItalic)
}
}
#endif
......@@ -251,6 +251,9 @@ public class WOPAlert: Object, MapContext, Mappable {
@objc public dynamic var created = ""
@objc public dynamic var lastModified = ""
@objc public dynamic var urgency = ""
@objc public dynamic var subject = ""
@objc public dynamic var body = ""
@objc public dynamic var url = ""
@objc public dynamic var message = ""
@objc public dynamic var startDate = ""
@objc public dynamic var endDate = ""
......@@ -264,6 +267,9 @@ public class WOPAlert: Object, MapContext, Mappable {
created <- map["created"]
lastModified <- map["modified"]
urgency <- map["urgency_tag"]
subject <- map["subject"]
body <- map["body"]
message <- map["url"]
message <- map["message"]
startDate <- map["start_datetime"]
endDate <- map["end_datetime"]
......
......@@ -136,13 +136,19 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" textAlignment="natural" adjustsFontForContentSizeCategory="YES" translatesAutoresizingMaskIntoConstraints="NO" id="RN8-f7-qjd">
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" usesAttributedText="YES" adjustsFontForContentSizeCategory="YES" translatesAutoresizingMaskIntoConstraints="NO" id="RN8-f7-qjd">
<rect key="frame" x="16" y="94" width="343" height="553"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<string key="text">Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.</string>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<attributedString key="attributedText">
<fragment>
<string key="content">Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.</string>
<attributes>
<font key="NSFont" metaFont="system" size="20"/>
</attributes>
</fragment>
</attributedString>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
<dataDetectorType key="dataDetectorTypes" phoneNumber="YES" link="YES"/>
<dataDetectorType key="dataDetectorTypes" phoneNumber="YES" link="YES" address="YES"/>
</textView>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="major" translatesAutoresizingMaskIntoConstraints="NO" id="7p3-a2-wz4">
<rect key="frame" x="16" y="22" width="64" height="64"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment