Skip to content

Commit 04297e8

Browse files
authored
Merge pull request #754 from woocommerce/issue/751-crash-on-log-out
Issue/751 crash on log out
2 parents 893f07a + 3c1351a commit 04297e8

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
1.4
22
-----
3+
- bugfix: fix a crash happening on log out
34
- new feature: Add shipment tracking to Order Details screen
45
- improvement: The store switcher now allows you to go back to the previous screen without logging you out
56
- improvement: Custom order status labels are now supported! Instead of just displaying the order status slug and capitalizing the slug, the custom order status label will now be fetched from the server and properly displayed.

WooCommerce/Classes/System/SessionManager.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ extension NSNotification.Name {
1212
///
1313
public static let defaultAccountWasUpdated = Foundation.Notification.Name(rawValue: "DefaultAccountWasUpdated")
1414

15+
/// Posted after a Log out event happens.
16+
///
17+
public static let logOutEventReceived = Foundation.Notification.Name(rawValue: "LogOutEventReceived")
18+
1519
/// Posted whenever the app is about to terminate.
1620
///
1721
public static let applicationTerminating = Foundation.Notification.Name(rawValue: "ApplicationTerminating")

WooCommerce/Classes/ViewRelated/Orders/OrdersViewController.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,16 @@ private extension OrdersViewController {
195195
/// Setup: Order status predicate
196196
///
197197
func refreshStatusPredicate() {
198+
// Bugfix for https://github.com/woocommerce/woocommerce-ios/issues/751.
199+
// Because we are listening for default account changes,
200+
// this will also fire upon logging out, when the account
201+
// is set to nil. So let's protect against multi-threaded
202+
// access attempts if the account is indeed nil.
203+
guard StoresManager.shared.isAuthenticated,
204+
StoresManager.shared.needsDefaultStore == false else {
205+
return
206+
}
207+
198208
statusResultsController.predicate = NSPredicate(format: "siteID == %lld", StoresManager.shared.sessionManager.defaultStoreID ?? Int.min)
199209
}
200210

@@ -291,11 +301,12 @@ extension OrdersViewController {
291301
func startListeningToNotifications() {
292302
let nc = NotificationCenter.default
293303
nc.addObserver(self, selector: #selector(defaultAccountWasUpdated), name: .defaultAccountWasUpdated, object: nil)
304+
nc.addObserver(self, selector: #selector(stopListeningToNotifications), name: .logOutEventReceived, object: nil)
294305
}
295306

296307
/// Stops listening to all related Notifications
297308
///
298-
func stopListeningToNotifications() {
309+
@objc func stopListeningToNotifications() {
299310
NotificationCenter.default.removeObserver(self)
300311
}
301312

WooCommerce/Classes/Yosemite/StoresManager.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ class StoresManager {
123123
ZendeskManager.shared.reset()
124124
AppDelegate.shared.storageManager.reset()
125125

126+
NotificationCenter.default.post(name: .logOutEventReceived, object: nil)
127+
126128
return self
127129
}
128130

0 commit comments

Comments
 (0)