<BlockSwitcher>

<Block name="Listener (iOS 11+)">

```swift
let hubEventListener = Amplify.Hub.listen(to: .dataStore) { event in
    if event.eventName == HubPayload.EventName.DataStore.networkStatus {
        guard let networkStatus = event.data as? NetworkStatusEvent else {
            print("Failed to cast data as NetworkStatusEvent")
            return
        }
        print("User receives a network connection status: \(networkStatus.active)")
    }
}
```

</Block>

<Block name="Combine (iOS 13+)">

```swift
let hubEventSubscriber = Amplify.Hub.publisher(for: .dataStore).sink { event in
    if event.eventName == HubPayload.EventName.DataStore.networkStatus {
        guard let networkStatus = event.data as? NetworkStatusEvent else {
            print("Failed to cast data as NetworkStatusEvent")
            return
        }
        print("User receives a network connection status: \(networkStatus.active)")
    }
}
```

</Block>

</BlockSwitcher>

<Callout>

An initial `networkStatus` event is always dispatched, in which `active` is set to `false`. Shortly thereafter, you will receive an updated event that reflects the true status of the network connectivity.

</Callout>

<Callout>

You may want to setup your Hub Listener or Subscriber before calling `Amplify.configure()`, otherwise you may miss some of the `DataStore` events that are emitted.

</Callout>