Skip to content

Commit

Permalink
improve notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiet480 committed Apr 23, 2017
1 parent 49ec1bb commit fc4aa02
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion HomeAssistant/AppDelegate.swift
Expand Up @@ -306,6 +306,6 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
// swiftlint:disable:next line_length
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
print("Received notification!")
completionHandler([.alert, .badge, .sound])
return completionHandler([.alert, .badge, .sound])
}
}
5 changes: 1 addition & 4 deletions HomeAssistant/HAAPI.swift
Expand Up @@ -1013,10 +1013,7 @@ public class HomeAssistantAPI {
}

var notificationsEnabled: Bool {
// return PermissionScope().statusNotifications() == .authorized && prefs.string(forKey: "pushID") != nil
return prefs.string(forKey: "pushID") != nil
// print("PermissionScope().statusNotifications()", PermissionScope().statusNotifications())
// return PermissionScope().statusNotifications() == .authorized
return prefs.bool(forKey: "notificationsEnabled")
}

var iosComponentLoaded: Bool {
Expand Down
7 changes: 5 additions & 2 deletions HomeAssistant/Views/SettingsViewController.swift
Expand Up @@ -339,6 +339,8 @@ class SettingsViewController: FormViewController {
if finished {
print("Notifications Permissions finished!", finished, results)
if results[0].status == .authorized {
prefs.setValue(true, forKey: "notificationsEnabled")
prefs.synchronize()
HomeAssistantAPI.sharedInstance.setupPush()
row.hidden = true
row.evaluateHidden()
Expand All @@ -349,6 +351,9 @@ class SettingsViewController: FormViewController {
notifyPlatformLoadedRow.hidden = false
notifyPlatformLoadedRow.evaluateHidden()
self.tableView.reloadData()
} else {
prefs.setValue(false, forKey: "notificationsEnabled")
prefs.synchronize()
}
}
}, cancelled: { _ -> Void in
Expand All @@ -360,8 +365,6 @@ class SettingsViewController: FormViewController {
$0.title = L10n.Settings.DetailsSection.NotificationSettingsRow.title
$0.hidden = Condition(booleanLiteral: !HomeAssistantAPI.sharedInstance.notificationsEnabled)
$0.presentationMode = .show(controllerProvider: ControllerProvider.callback {
print("HomeAssistantAPI.sharedInstance.notificationsEnabled",
HomeAssistantAPI.sharedInstance.notificationsEnabled)
let view = SettingsDetailViewController()
view.detailGroup = "notifications"
return view
Expand Down
4 changes: 2 additions & 2 deletions MapNotificationContentExtension/Info.plist
Expand Up @@ -22,15 +22,15 @@
<string>3</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionAttributes</key>
<dict>
<key>UNNotificationExtensionCategory</key>
<string>map</string>
<key>UNNotificationExtensionInitialContentSizeRatio</key>
<real>1</real>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.usernotifications.content-extension</string>
</dict>
Expand Down

0 comments on commit fc4aa02

Please sign in to comment.