Skip to content

ios: react to change in connectivity. #3428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions backend/mobileserver/mobileserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ func UsingMobileDataChanged() {
bridgecommon.UsingMobileDataChanged()
}

// SetOnline exposes `bridgecommon.SetOnline` to Java/Kotlin.
func SetOnline(online bool) {
bridgecommon.SetOnline(online)
}

// UsbUpdate exposes `bridgecommon.UsbUpdate` to Java/Kotlin.
func UsbUpdate() {
bridgecommon.UsbUpdate()
Expand Down
6 changes: 6 additions & 0 deletions frontends/ios/BitBoxApp/BitBoxApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
8E1846EB2E0AFF6000802D8B /* NetworkMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E1846EA2E0AFF5B00802D8B /* NetworkMonitor.swift */; };
8E1846EC2E0AFF6000802D8B /* NetworkMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E1846EA2E0AFF5B00802D8B /* NetworkMonitor.swift */; };
D700B5F62C884C34000496D4 /* Mobileserver.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D76518BB2B1F8F7400DC03A9 /* Mobileserver.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
D700B5FD2CA2FFAF000496D4 /* WebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D76516322B1F3D1A00DC03A9 /* WebView.swift */; };
D700B5FE2CA2FFAF000496D4 /* BitBoxAppApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D76516082B1F3B1300DC03A9 /* BitBoxAppApp.swift */; };
Expand Down Expand Up @@ -71,6 +73,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
8E1846EA2E0AFF5B00802D8B /* NetworkMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkMonitor.swift; sourceTree = "<group>"; };
D700B5F82C888CB9000496D4 /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
D700B5F92C986A3C000496D4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
D700B60A2CA2FFAF000496D4 /* BitBoxApp Testnet.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "BitBoxApp Testnet.app"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -151,6 +154,7 @@
D76516072B1F3B1300DC03A9 /* BitBoxApp */ = {
isa = PBXGroup;
children = (
8E1846EA2E0AFF5B00802D8B /* NetworkMonitor.swift */,
D700B5F92C986A3C000496D4 /* Info.plist */,
D76518B52B1F45B300DC03A9 /* assets */,
D76516082B1F3B1300DC03A9 /* BitBoxAppApp.swift */,
Expand Down Expand Up @@ -400,6 +404,7 @@
buildActionMask = 2147483647;
files = (
D700B5FD2CA2FFAF000496D4 /* WebView.swift in Sources */,
8E1846EC2E0AFF6000802D8B /* NetworkMonitor.swift in Sources */,
D721B20E2D36A00000767080 /* Bluetooth.swift in Sources */,
D700B5FE2CA2FFAF000496D4 /* BitBoxAppApp.swift in Sources */,
);
Expand All @@ -410,6 +415,7 @@
buildActionMask = 2147483647;
files = (
D76516332B1F3D1B00DC03A9 /* WebView.swift in Sources */,
8E1846EB2E0AFF6000802D8B /* NetworkMonitor.swift in Sources */,
D721B20D2D369EC100767080 /* Bluetooth.swift in Sources */,
D76516092B1F3B1300DC03A9 /* BitBoxAppApp.swift in Sources */,
);
Expand Down
3 changes: 3 additions & 0 deletions frontends/ios/BitBoxApp/BitBoxApp/BitBoxAppApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import SwiftUI
import Mobileserver
import LocalAuthentication
import Network

protocol MessageHandlersProtocol {
func callResponseHandler(queryID: Int, response: String)
Expand Down Expand Up @@ -184,6 +185,8 @@ struct BitBoxAppApp: App {
.edgesIgnoringSafeArea(.all)
.onAppear {
setupGoAPI(goAPI: goAPI)
// Manual trigger at startup
MobileserverSetOnline(NetworkMonitor.shared.isOnline())
}
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
MobileserverManualReconnect()
Expand Down
27 changes: 27 additions & 0 deletions frontends/ios/BitBoxApp/BitBoxApp/NetworkMonitor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// NetworkMonitor.swift
// BitBoxApp
//
// Created by Nikolas De Giorgis on 24/06/2025.
//

import Network
import Mobileserver

class NetworkMonitor {
static let shared = NetworkMonitor()
private let monitor = NWPathMonitor()
private let queue = DispatchQueue(label: "NetworkMonitor")

private init() {
monitor.pathUpdateHandler = { path in
let isOnline = self.isOnline()
MobileserverSetOnline(isOnline)
}
monitor.start(queue: queue)
}

func isOnline() -> Bool {
return monitor.currentPath.status == .satisfied
}
}