diff --git a/watch_connectivity/CHANGELOG.md b/watch_connectivity/CHANGELOG.md index e52eecb..3be3196 100644 --- a/watch_connectivity/CHANGELOG.md +++ b/watch_connectivity/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.7 + +- Add `isWatchAppInstalled` method + ## 0.2.6 - Fixes NPE on hot reload diff --git a/watch_connectivity/android/src/main/kotlin/dev/rexios/watch_connectivity/WatchConnectivityPlugin.kt b/watch_connectivity/android/src/main/kotlin/dev/rexios/watch_connectivity/WatchConnectivityPlugin.kt index 8c6938b..814945f 100644 --- a/watch_connectivity/android/src/main/kotlin/dev/rexios/watch_connectivity/WatchConnectivityPlugin.kt +++ b/watch_connectivity/android/src/main/kotlin/dev/rexios/watch_connectivity/WatchConnectivityPlugin.kt @@ -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) @@ -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 { diff --git a/watch_connectivity/ios/Classes/SwiftWatchConnectivityPlugin.swift b/watch_connectivity/ios/Classes/SwiftWatchConnectivityPlugin.swift index cb77f25..bada136 100644 --- a/watch_connectivity/ios/Classes/SwiftWatchConnectivityPlugin.swift +++ b/watch_connectivity/ios/Classes/SwiftWatchConnectivityPlugin.swift @@ -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": diff --git a/watch_connectivity/lib/src/watch_connectivity_base.dart b/watch_connectivity/lib/src/watch_connectivity_base.dart index 306ddf9..d7b79e3 100644 --- a/watch_connectivity/lib/src/watch_connectivity_base.dart +++ b/watch_connectivity/lib/src/watch_connectivity_base.dart @@ -17,6 +17,12 @@ class WatchConnectivity extends WatchConnectivityBase { @override Future get isReachable => super.isReachable; + /// Apple Watch: If the watch app is installed + /// + /// WearOS: If any connected nodes exist (best-effort check) + @override + Future 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 diff --git a/watch_connectivity/pubspec.yaml b/watch_connectivity/pubspec.yaml index 3a14c7a..faa587a 100644 --- a/watch_connectivity/pubspec.yaml +++ b/watch_connectivity/pubspec.yaml @@ -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: @@ -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: diff --git a/watch_connectivity_platform_interface/CHANGELOG.md b/watch_connectivity_platform_interface/CHANGELOG.md index 42d35c2..b5a9ef7 100644 --- a/watch_connectivity_platform_interface/CHANGELOG.md +++ b/watch_connectivity_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.3.1 + +- Add `isWatchAppInstalled` method + ## 0.3.0 - Replace `MethodChannel` with `EventChannel` for messages from the host platform diff --git a/watch_connectivity_platform_interface/lib/src/watch_connectivity_platform_interface_base.dart b/watch_connectivity_platform_interface/lib/src/watch_connectivity_platform_interface_base.dart index 5dc565e..2ed7711 100644 --- a/watch_connectivity_platform_interface/lib/src/watch_connectivity_platform_interface_base.dart +++ b/watch_connectivity_platform_interface/lib/src/watch_connectivity_platform_interface_base.dart @@ -58,6 +58,12 @@ abstract class WatchConnectivityBase { return reachable ?? false; } + /// If the watch app is installed + Future get isWatchAppInstalled async { + final installed = await methodChannel.invokeMethod('isWatchAppInstalled'); + return installed ?? false; + } + /// The most recently sent contextual data Future> get applicationContext async { final applicationContext = await methodChannel diff --git a/watch_connectivity_platform_interface/pubspec.yaml b/watch_connectivity_platform_interface/pubspec.yaml index dfc301f..072206f 100644 --- a/watch_connectivity_platform_interface/pubspec.yaml +++ b/watch_connectivity_platform_interface/pubspec.yaml @@ -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: