Skip to content
This repository was archived by the owner on Feb 27, 2019. It is now read-only.

Commit fcc6ef2

Browse files
committed
Notifications not immediately updated.
1 parent d340441 commit fcc6ef2

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

PermissionScope-example/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ViewController: UIViewController {
2020

2121
singlePscope.addPermission(NotificationsPermission(notificationCategories: nil),
2222
message: "We use this to send you\r\nspam and love notes")
23-
23+
2424
multiPscope.addPermission(ContactsPermission(),
2525
message: "We use this to steal\r\nyour friends")
2626
multiPscope.addPermission(NotificationsPermission(notificationCategories: nil),

PermissionScope/PermissionScope.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -599,15 +599,17 @@ typealias resultsForConfigClosure = ([PermissionResult]) -> Void
599599

600600
defaults.setBool(true, forKey: Constants.NSUserDefaultsKeys.requestedNotifications)
601601
defaults.synchronize()
602-
603-
getResultsForConfig { results in
604-
guard let notificationResult = results
605-
.first({ $0.type == .Notifications }) else { return }
606-
607-
if notificationResult.status == .Unknown {
608-
self.showDeniedAlert(notificationResult.type)
609-
} else {
610-
self.detectAndCallback()
602+
603+
dispatch_async(dispatch_get_main_queue()) {
604+
self.getResultsForConfig { results in
605+
guard let notificationResult = results
606+
.first({ $0.type == .Notifications }) else { return }
607+
608+
if notificationResult.status == .Unknown {
609+
self.showDeniedAlert(notificationResult.type)
610+
} else {
611+
self.detectAndCallback()
612+
}
611613
}
612614
}
613615
}
@@ -994,13 +996,13 @@ typealias resultsForConfigClosure = ([PermissionResult]) -> Void
994996
// call other methods that need to wait before show
995997
// no missing required perms? callback and do nothing
996998
self.requiredAuthorized({ areAuthorized in
997-
998999
if areAuthorized {
9991000
self.getResultsForConfig({ results in
1001+
10001002
self.onAuthChange?(finished: true, results: results)
10011003
})
10021004
} else {
1003-
self.showAlert()
1005+
self.showAlert()
10041006
}
10051007
})
10061008
}

0 commit comments

Comments
 (0)