Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions watch_connectivity/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.7

- Add `isWatchAppInstalled` method

## 0.2.6

- Fixes NPE on hot reload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class WatchConnectivityPlugin : FlutterPlugin, MethodCallHandler,
"isSupported" -> result.success(true)
"isPaired" -> isPaired(result)
"isReachable" -> isReachable(result)
"isWatchAppInstalled" -> isWatchAppInstalled(result)
"applicationContext" -> applicationContext(result)
"receivedApplicationContexts" -> receivedApplicationContexts(result)

Expand Down Expand Up @@ -112,6 +113,16 @@ class WatchConnectivityPlugin : FlutterPlugin, MethodCallHandler,
.addOnFailureListener { result.error(it.message ?: "", it.localizedMessage, it) }
}

private fun isWatchAppInstalled(result: Result) {
// Check if any connected node has the watch app installed
// For WearOS, we check if there are connected nodes with the app
nodeClient.connectedNodes.addOnSuccessListener { nodes ->
// If there are connected nodes, the watch app is likely installed
// This is a best-effort check for WearOS
result.success(nodes.isNotEmpty())
}.addOnFailureListener { result.error(it.message ?: "", it.localizedMessage, it) }
}

private fun applicationContext(result: Result) {
dataClient.dataItems.addOnSuccessListener { items ->
val localNodeItem = items.firstOrNull {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class SwiftWatchConnectivityPlugin: NSObject, FlutterPlugin, WCSessionDel
result(session?.isPaired ?? false)
case "isReachable":
result(session?.isReachable ?? false)
case "isWatchAppInstalled":
result(session?.isWatchAppInstalled ?? false)
case "applicationContext":
result(session?.applicationContext ?? [:])
case "receivedApplicationContexts":
Expand Down
6 changes: 6 additions & 0 deletions watch_connectivity/lib/src/watch_connectivity_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class WatchConnectivity extends WatchConnectivityBase {
@override
Future<bool> get isReachable => super.isReachable;

/// Apple Watch: If the watch app is installed
///
/// WearOS: If any connected nodes exist (best-effort check)
@override
Future<bool> get isWatchAppInstalled => super.isWatchAppInstalled;

/// Apple Watch: This will only ever contain one map
///
/// WearOS: This will contain one map for every node that has sent a context
Expand Down
4 changes: 2 additions & 2 deletions watch_connectivity/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: watch_connectivity
description: Wrapper for WatchConnectivity on iOS and Wearable APIs on Android
version: 0.2.6
version: 0.2.7
homepage: https://github.com/Rexios80/watch_connectivity/tree/master/watch_connectivity

environment:
Expand All @@ -11,7 +11,7 @@ dependencies:
flutter:
sdk: flutter

watch_connectivity_platform_interface: ^0.3.0
watch_connectivity_platform_interface: ^0.3.1

dev_dependencies:
flutter_test:
Expand Down
4 changes: 4 additions & 0 deletions watch_connectivity_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.1

- Add `isWatchAppInstalled` method

## 0.3.0

- Replace `MethodChannel` with `EventChannel` for messages from the host platform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ abstract class WatchConnectivityBase {
return reachable ?? false;
}

/// If the watch app is installed
Future<bool> get isWatchAppInstalled async {
final installed = await methodChannel.invokeMethod<bool>('isWatchAppInstalled');
return installed ?? false;
}

/// The most recently sent contextual data
Future<Map<String, dynamic>> get applicationContext async {
final applicationContext = await methodChannel
Expand Down
2 changes: 1 addition & 1 deletion watch_connectivity_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: watch_connectivity_platform_interface
description: Platform interface for communicating with wearable watch devices
version: 0.3.0
version: 0.3.1
homepage: https://github.com/Rexios80/watch_connectivity/tree/master/watch_connectivity_platform_interface

environment:
Expand Down