Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ln-12/multiplatform-connectivity-status
A Kotlin multiplatform mobile library to monitor the connectivity status of the device
https://github.com/ln-12/multiplatform-connectivity-status
Last synced: 2 months ago
JSON representation
A Kotlin multiplatform mobile library to monitor the connectivity status of the device
- Host: GitHub
- URL: https://github.com/ln-12/multiplatform-connectivity-status
- Owner: ln-12
- License: apache-2.0
- Created: 2021-02-02T09:17:41.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-22T13:16:37.000Z (over 2 years ago)
- Last Synced: 2024-08-02T09:26:27.024Z (6 months ago)
- Language: Kotlin
- Size: 178 KB
- Stars: 63
- Watchers: 3
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-kotlin-multiplatform - Connectivity status - Monitor the internet connection status of your device on Android and iOS. (Libraries / Network)
- kmp-awesome - Connectivity status - Multiplatform connectivity status (Libraries / 📱 Device)
README
# Multiplatform connectivity status
This Kotlin multiplatform mobile utility library allows monitoring the internet connection status of the device. You can use it from shared code as well as directly from Android or iOS code.
The project structure is taken from [this well explained and detailed tutorial](https://dev.to/kotlin/how-to-build-and-publish-a-kotlin-multiplatform-library-creating-your-first-library-1bp8
).
## InstallationAdd `mavenCentral()` to your repositories:
``` kotlin
buildscript {
repositories {
// ... other repositories
mavenCentral()
}
}
```Add the library to your project:
``` kotlin
kotlin {
android()
ios()sourceSets {
val commonMain by getting {
dependencies {
implementation("com.github.ln-12:multiplatform-connectivity-status:1.2.0")
}
}
}
}
```On iOS, you also have to add the [Reachability](https://github.com/tonymillion/Reachability) pod to your Podfile:
```
target 'iosApp' do
pod 'Reachability'
end
```## Usage
``` kotlin
// get the satus object, on Android provide a context
val connectivityStatus = ConnectivityStatus()// output changes
connectivityStatus.isNetworkConnected.collect {
printnl("New status $it")
}// start monitoring
connectivityStatus.start()// some code from your project
// when you are done, stop it
connectivityStatus.stop()
```On iOS, you can also use this `getStatus()` closure to observe changes:
```swift
connectivityStatus.getStatus(success: { status in
print(status.boolValue)
})
```## Sample
You can find a sample Android and iOS app inside the [sample](./sample) directory.
## License
Copyright 2022 Lorenzo Neumann
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.