diff --git a/ios/BlueWallet/AppDelegate.mm b/ios/BlueWallet/AppDelegate.mm
index f81de4923..36130e9a7 100644
--- a/ios/BlueWallet/AppDelegate.mm
+++ b/ios/BlueWallet/AppDelegate.mm
@@ -103,7 +103,7 @@
}
- (void)applicationWillTerminate:(UIApplication *)application {
- if ([[WCSession defaultSession] isReachable]) {
+ if ([WCSession defaultSession].activationState == WCSessionActivationStateActivated && [[WCSession defaultSession] isReachable]) {
[WCSession.defaultSession updateApplicationContext:@{@"isWalletsInitialized": @NO} error:nil];
}
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.io.bluewallet.bluewallet"];
diff --git a/ios/BlueWallet/Info.plist b/ios/BlueWallet/Info.plist
index ddfd6e289..f251a1a9c 100644
--- a/ios/BlueWallet/Info.plist
+++ b/ios/BlueWallet/Info.plist
@@ -176,6 +176,7 @@
UIBackgroundModes
+ fetch
remote-notification
UILaunchStoryboardName
diff --git a/ios/BlueWalletWatch Extension/InterfaceController.swift b/ios/BlueWalletWatch Extension/InterfaceController.swift
index 31d6abb1a..a63ec831a 100644
--- a/ios/BlueWalletWatch Extension/InterfaceController.swift
+++ b/ios/BlueWalletWatch Extension/InterfaceController.swift
@@ -10,12 +10,23 @@ import WatchKit
import WatchConnectivity
import Foundation
-class InterfaceController: WKInterfaceController {
+class InterfaceController: WKInterfaceController, WCSessionDelegate {
@IBOutlet weak var walletsTable: WKInterfaceTable!
@IBOutlet weak var noWalletsAvailableLabel: WKInterfaceLabel!
private let userActivity: NSUserActivity = NSUserActivity(activityType: HandoffIdentifier.ReceiveOnchain.rawValue)
-
+ var session: WCSession?
+
+ override func awake(withContext context: Any?) {
+ super.awake(withContext: context)
+ if WCSession.isSupported() {
+ print("Activating watch session")
+ self.session = WCSession.default
+ self.session?.delegate = self
+ self.session?.activate()
+ }
+ }
+
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
@@ -54,4 +65,26 @@ class InterfaceController: WKInterfaceController {
return rowIndex;
}
+ func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
+ WatchDataSource.shared.processData(data: applicationContext)
+ }
+
+ func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) {
+ WatchDataSource.shared.processData(data: applicationContext)
+ }
+
+ func session(_ session: WCSession, didReceiveUserInfo userInfo: [String : Any] = [:]) {
+ WatchDataSource.shared.processData(data: userInfo)
+ }
+
+ func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
+ if activationState == .activated {
+ WCSession.default.sendMessage(["message" : "sendApplicationContext"], replyHandler: { (replyData) in
+ }) { (error) in
+ print(error)
+ }
+ } else {
+ WatchDataSource.shared.companionWalletsInitialized = false
+ }
+ }
}
diff --git a/ios/BlueWalletWatch Extension/Objects/WatchDataSource.swift b/ios/BlueWalletWatch Extension/Objects/WatchDataSource.swift
index 93bd98fd2..039b0e152 100644
--- a/ios/BlueWalletWatch Extension/Objects/WatchDataSource.swift
+++ b/ios/BlueWalletWatch Extension/Objects/WatchDataSource.swift
@@ -10,7 +10,7 @@
import Foundation
import WatchConnectivity
-class WatchDataSource: NSObject, WCSessionDelegate {
+class WatchDataSource: NSObject {
struct NotificationName {
static let dataUpdated = Notification.Name(rawValue: "Notification.WalletDataSource.Updated")
}
@@ -30,11 +30,6 @@ class WatchDataSource: NSObject, WCSessionDelegate {
wallets = walletData
WatchDataSource.postDataUpdatedNotification()
}
- if WCSession.isSupported() {
- print("Activating watch session")
- WCSession.default.delegate = self
- WCSession.default.activate()
- }
}
func processWalletsData(walletsInfo: [String: Any]) {
@@ -100,14 +95,7 @@ class WatchDataSource: NSObject, WCSessionDelegate {
}
}
-
- func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
- processData(data: applicationContext)
- }
-
- func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) {
- processData(data: applicationContext)
- }
+
func processData(data: [String: Any]) {
if let preferredFiatCurrency = data["preferredFiatCurrency"] as? String, let preferredFiatCurrencyUnit = fiatUnit(currency: preferredFiatCurrency) {
@@ -122,19 +110,4 @@ class WatchDataSource: NSObject, WCSessionDelegate {
}
}
- func session(_ session: WCSession, didReceiveUserInfo userInfo: [String : Any] = [:]) {
- processData(data: userInfo)
- }
-
- func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
- if activationState == .activated {
- WCSession.default.sendMessage(["message" : "sendApplicationContext"], replyHandler: { (replyData) in
- }) { (error) in
- print(error)
- }
- } else {
- WatchDataSource.shared.companionWalletsInitialized = false
- }
- }
-
}
diff --git a/ios/BlueWalletWatch Extension/ViewQRCodefaceController.swift b/ios/BlueWalletWatch Extension/ViewQRCodefaceController.swift
index b2b6c8b48..44f634af0 100644
--- a/ios/BlueWalletWatch Extension/ViewQRCodefaceController.swift
+++ b/ios/BlueWalletWatch Extension/ViewQRCodefaceController.swift
@@ -40,7 +40,7 @@ class ViewQRCodefaceController: WKInterfaceController {
DispatchQueue.main.async {
guard let cgImage = EFQRCode.generate(
- content: passedContext) else {
+ for: passedContext) else {
return
}
let image = UIImage(cgImage: cgImage)