diff --git a/AcaiaExamples.xcodeproj/project.pbxproj b/AcaiaExamples.xcodeproj/project.pbxproj index 041b13b..54304a5 100644 --- a/AcaiaExamples.xcodeproj/project.pbxproj +++ b/AcaiaExamples.xcodeproj/project.pbxproj @@ -22,8 +22,6 @@ 8E92FFA12339CA3900BC995C /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E92FF992339CA3900BC995C /* ViewController.m */; }; 997899862828E9C600352E8B /* AcaiaSDK.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 997899852828E9C600352E8B /* AcaiaSDK.xcframework */; }; 997899872828E9C600352E8B /* AcaiaSDK.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 997899852828E9C600352E8B /* AcaiaSDK.xcframework */; }; - 9978998A2828EA1400352E8B /* MBProgressHUD in Frameworks */ = {isa = PBXBuildFile; productRef = 997899892828EA1400352E8B /* MBProgressHUD */; }; - 9978998C2828EA1D00352E8B /* MBProgressHUD in Frameworks */ = {isa = PBXBuildFile; productRef = 9978998B2828EA1D00352E8B /* MBProgressHUD */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -44,10 +42,9 @@ 8E6E186A2339D041005633C5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = LaunchScreen.storyboard; sourceTree = ""; }; 8E6E186C2339D041005633C5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Main.storyboard; sourceTree = ""; }; 8E6E186D2339D041005633C5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 8E6E186E2339D041005633C5 /* Example-swift test framework.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Example-swift test framework.plist"; sourceTree = ""; }; + 8E6E186E2339D041005633C5 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 8E6E186F2339D041005633C5 /* AcaiaViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AcaiaViewController.swift; sourceTree = ""; }; 8E6E18702339D041005633C5 /* AcaiaScaleTableVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AcaiaScaleTableVC.swift; sourceTree = ""; }; - 8E7924D223447F8C00578CBE /* Example-swift test source.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Example-swift test source.plist"; sourceTree = ""; }; 8E7925292344839A00578CBE /* Example-swift test source-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Example-swift test source-Bridging-Header.h"; sourceTree = ""; }; 8E92FF7A2339CA0400BC995C /* Example-swift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Example-swift.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 8E92FF8C2339CA3900BC995C /* AcaiaScaleTableVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AcaiaScaleTableVC.h; sourceTree = ""; }; @@ -70,7 +67,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 9978998C2828EA1D00352E8B /* MBProgressHUD in Frameworks */, 997899872828E9C600352E8B /* AcaiaSDK.xcframework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -79,7 +75,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 9978998A2828EA1400352E8B /* MBProgressHUD in Frameworks */, 997899862828E9C600352E8B /* AcaiaSDK.xcframework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -124,8 +119,7 @@ 8E92FF7B2339CA0400BC995C /* Example-swift */ = { isa = PBXGroup; children = ( - 8E6E186E2339D041005633C5 /* Example-swift test framework.plist */, - 8E7924D223447F8C00578CBE /* Example-swift test source.plist */, + 8E6E186E2339D041005633C5 /* Info.plist */, 8E7925292344839A00578CBE /* Example-swift test source-Bridging-Header.h */, 8E6E18702339D041005633C5 /* AcaiaScaleTableVC.swift */, 8E6E186F2339D041005633C5 /* AcaiaViewController.swift */, @@ -182,7 +176,6 @@ ); name = "Example-swift"; packageProductDependencies = ( - 9978998B2828EA1D00352E8B /* MBProgressHUD */, ); productName = "Example-swift"; productReference = 8E92FF7A2339CA0400BC995C /* Example-swift.app */; @@ -202,7 +195,6 @@ ); name = "Example-objc"; packageProductDependencies = ( - 997899892828EA1400352E8B /* MBProgressHUD */, ); productName = AcaiaSample; productReference = 8EDCD15E2339C9190029329D /* Example-objc.app */; @@ -237,7 +229,6 @@ ); mainGroup = 8EDCD1552339C9190029329D; packageReferences = ( - 997899882828EA1400352E8B /* XCRemoteSwiftPackageReference "MBProgressHUD" */, ); productRefGroup = 8EDCD15F2339C9190029329D /* Products */; projectDirPath = ""; @@ -343,7 +334,7 @@ "$(inherited)", "$(PROJECT_DIR)", ); - INFOPLIST_FILE = "${PROJECT_DIR}/Example-swift/Example-swift test framework.plist"; + INFOPLIST_FILE = "${PROJECT_DIR}/Example-swift/Info.plist"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -367,7 +358,7 @@ "$(inherited)", "$(PROJECT_DIR)", ); - INFOPLIST_FILE = "${PROJECT_DIR}/Example-swift/Example-swift test framework.plist"; + INFOPLIST_FILE = "${PROJECT_DIR}/Example-swift/Info.plist"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -432,7 +423,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -489,7 +480,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = iphoneos; @@ -574,30 +565,6 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ - -/* Begin XCRemoteSwiftPackageReference section */ - 997899882828EA1400352E8B /* XCRemoteSwiftPackageReference "MBProgressHUD" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/jdg/MBProgressHUD"; - requirement = { - kind = upToNextMajorVersion; - minimumVersion = 1.0.0; - }; - }; -/* End XCRemoteSwiftPackageReference section */ - -/* Begin XCSwiftPackageProductDependency section */ - 997899892828EA1400352E8B /* MBProgressHUD */ = { - isa = XCSwiftPackageProductDependency; - package = 997899882828EA1400352E8B /* XCRemoteSwiftPackageReference "MBProgressHUD" */; - productName = MBProgressHUD; - }; - 9978998B2828EA1D00352E8B /* MBProgressHUD */ = { - isa = XCSwiftPackageProductDependency; - package = 997899882828EA1400352E8B /* XCRemoteSwiftPackageReference "MBProgressHUD" */; - productName = MBProgressHUD; - }; -/* End XCSwiftPackageProductDependency section */ }; rootObject = 8EDCD1562339C9190029329D /* Project object */; } diff --git a/AcaiaExamples.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/AcaiaExamples.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved deleted file mode 100644 index 28f8d98..0000000 --- a/AcaiaExamples.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ /dev/null @@ -1,14 +0,0 @@ -{ - "pins" : [ - { - "identity" : "mbprogresshud", - "kind" : "remoteSourceControl", - "location" : "https://github.com/jdg/MBProgressHUD", - "state" : { - "revision" : "bca42b801100b2b3a4eda0ba8dd33d858c780b0d", - "version" : "1.2.0" - } - } - ], - "version" : 2 -} diff --git a/AcaiaSDK.xcframework/Info.plist b/AcaiaSDK.xcframework/Info.plist index 69cc640..1f6a5b6 100644 --- a/AcaiaSDK.xcframework/Info.plist +++ b/AcaiaSDK.xcframework/Info.plist @@ -6,30 +6,30 @@ LibraryIdentifier - ios-arm64 + ios-arm64_x86_64-simulator LibraryPath AcaiaSDK.framework SupportedArchitectures arm64 + x86_64 SupportedPlatform ios + SupportedPlatformVariant + simulator LibraryIdentifier - ios-arm64_x86_64-simulator + ios-arm64 LibraryPath AcaiaSDK.framework SupportedArchitectures arm64 - x86_64 SupportedPlatform ios - SupportedPlatformVariant - simulator CFBundlePackageType diff --git a/AcaiaSDK.xcframework/ios-arm64/AcaiaSDK.framework/AcaiaSDK b/AcaiaSDK.xcframework/ios-arm64/AcaiaSDK.framework/AcaiaSDK index 5efcf47..6c93ff9 100644 Binary files a/AcaiaSDK.xcframework/ios-arm64/AcaiaSDK.framework/AcaiaSDK and b/AcaiaSDK.xcframework/ios-arm64/AcaiaSDK.framework/AcaiaSDK differ diff --git a/AcaiaSDK.xcframework/ios-arm64/AcaiaSDK.framework/Info.plist b/AcaiaSDK.xcframework/ios-arm64/AcaiaSDK.framework/Info.plist index 221e966..a2f00b5 100644 Binary files a/AcaiaSDK.xcframework/ios-arm64/AcaiaSDK.framework/Info.plist and b/AcaiaSDK.xcframework/ios-arm64/AcaiaSDK.framework/Info.plist differ diff --git a/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/AcaiaSDK b/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/AcaiaSDK index 257a51a..8fd6e5a 100644 Binary files a/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/AcaiaSDK and b/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/AcaiaSDK differ diff --git a/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/Info.plist b/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/Info.plist index 7ba9279..2376f98 100644 Binary files a/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/Info.plist and b/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/Info.plist differ diff --git a/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/_CodeSignature/CodeDirectory b/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/_CodeSignature/CodeDirectory index 7090d4a..0494724 100644 Binary files a/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/_CodeSignature/CodeDirectory and b/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/_CodeSignature/CodeDirectory differ diff --git a/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/_CodeSignature/CodeRequirements-1 b/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/_CodeSignature/CodeRequirements-1 index 7febc4d..df569b1 100644 Binary files a/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/_CodeSignature/CodeRequirements-1 and b/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/_CodeSignature/CodeRequirements-1 differ diff --git a/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/_CodeSignature/CodeResources b/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/_CodeSignature/CodeResources index 38fe4ff..8d68edd 100644 --- a/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/_CodeSignature/CodeResources +++ b/AcaiaSDK.xcframework/ios-arm64_x86_64-simulator/AcaiaSDK.framework/_CodeSignature/CodeResources @@ -14,7 +14,7 @@ Info.plist - hYF3vqXUIlBsYmK1xNwNirf8auY= + xuRMmdBXdDFCtnzAGlTBwxtooBI= Modules/module.modulemap diff --git a/Example-objc/AcaiaScaleTableVC.m b/Example-objc/AcaiaScaleTableVC.m index 84ba587..8c66cc1 100644 --- a/Example-objc/AcaiaScaleTableVC.m +++ b/Example-objc/AcaiaScaleTableVC.m @@ -9,11 +9,11 @@ #import "AcaiaScaleTableVC.h" #import "AppDelegate.h" @import AcaiaSDK; -@import MBProgressHUD; @interface AcaiaScaleTableVC () @property BOOL isRefreshed; @property NSTimer *timer; +@property UIActivityIndicatorView* activityIndicatorView; @end @implementation AcaiaScaleTableVC @@ -30,6 +30,12 @@ - (void)viewDidLoad { self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Scanning"]; self.tableView.refreshControl = self.refreshControl; + self.activityIndicatorView = [[UIActivityIndicatorView alloc] + initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge]; + self.activityIndicatorView.hidesWhenStopped = true; + self.activityIndicatorView.hidden = true; + [self.view addSubview:self.activityIndicatorView]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onConnect:) name:AcaiaScaleDidConnected @@ -44,9 +50,8 @@ - (void)viewDidLoad { object:nil]; } - -- (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; +- (void)viewWillAppear:(BOOL)animated { + self.activityIndicatorView.center = self.view.center; } - (void)viewDidAppear:(BOOL)animated { @@ -55,13 +60,14 @@ - (void)viewDidAppear:(BOOL)animated { [[AcaiaManager sharedManager] startScan:0.5]; } -- (void)refresh:(UIRefreshControl *)refreshCtrl { - [[AcaiaManager sharedManager] startScan:0.5]; +- (void)viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; + + [[NSNotificationCenter defaultCenter] removeObserver:self]; } -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. +- (void)refresh:(UIRefreshControl *)refreshCtrl { + [[AcaiaManager sharedManager] startScan:0.5]; } #pragma mark - Acaia SDK Notification @@ -80,7 +86,7 @@ - (void) scanListChanged:(NSNotification *)noti { } - (void)onConnect:(NSNotification *)noti { - [MBProgressHUD hideHUDForView:self.view animated:true]; + [self.activityIndicatorView stopAnimating]; [self.navigationController popViewControllerAnimated:YES]; if (self.timer != nil) { [self.timer invalidate]; @@ -89,9 +95,22 @@ - (void)onConnect:(NSNotification *)noti { } - (void)onTimer:(NSTimer *)timer { - [MBProgressHUD hideHUDForView:self.view animated:true]; + [self.activityIndicatorView stopAnimating]; [self.timer invalidate]; self.timer = nil; + + [AcaiaManager.sharedManager startScan:0.1]; + + UIAlertController* alert = + [UIAlertController alertControllerWithTitle:nil + message:@"Connect timeout" + preferredStyle:UIAlertControllerStyleAlert]; + + [alert addAction:[UIAlertAction actionWithTitle:@"Ok" + style:UIAlertActionStyleCancel + handler:nil]]; + + [self presentViewController:alert animated:true completion:nil]; } #pragma mark - Table view data source @@ -127,8 +146,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath AcaiaScale* scale = [AcaiaManager sharedManager].scaleList[indexPath.row]; [scale connect]; - MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; - hud.label.text = [NSString stringWithFormat:@"Connecting to %@...", scale.name]; + [self.activityIndicatorView startAnimating]; } @end diff --git a/Example-objc/ViewController.m b/Example-objc/ViewController.m index 90cbf48..10d718d 100644 --- a/Example-objc/ViewController.m +++ b/Example-objc/ViewController.m @@ -7,7 +7,7 @@ // #import "ViewController.h" -#import +@import AcaiaSDK; @interface ViewController () @@ -84,7 +84,7 @@ - (void)onWeight:(NSNotification *)noti { } - (void)onTimer:(NSNotification *)noti { - NSNumber *timer = [[noti userInfo] objectForKey:@"time"]; + NSNumber *timer = [[noti userInfo] objectForKey:AcaiaScaleUserInfoKeyTimer]; NSInteger time = [timer integerValue]; self.timerL.text = [NSString stringWithFormat:@"%02lu:%02lu", time/60, time%60]; diff --git a/Example-swift/AcaiaScaleTableVC.swift b/Example-swift/AcaiaScaleTableVC.swift index 75502ee..a8fe3c2 100644 --- a/Example-swift/AcaiaScaleTableVC.swift +++ b/Example-swift/AcaiaScaleTableVC.swift @@ -7,7 +7,6 @@ // import UIKit -import MBProgressHUD import AcaiaSDK @@ -15,19 +14,9 @@ class AcaiaScaleTableVC: UITableViewController { override func viewDidLoad() { super.viewDidLoad() - } - - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - NotificationCenter.default.addObserver(self, - selector: #selector(_onConnect), - name: Notification.Name(rawValue: AcaiaScaleDidConnected), - object: nil) - NotificationCenter.default.addObserver(self, - selector: #selector(onFinishScan), - name: Notification.Name(rawValue: AcaiaScaleDidFinishScan), - object: nil) + _setRefreshControl() + _addAcaiaEventsObserver() } override func viewDidAppear(_ animated: Bool) { @@ -39,10 +28,13 @@ class AcaiaScaleTableVC: UITableViewController { override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) - NotificationCenter.default.removeObserver(self) + _activityIndicatorView.stopAnimating() + + _timerForConnectTimeOut?.invalidate() + _timerForConnectTimeOut = nil + + _removeScaleEventObservers() } - - // MARK: - Table view data source override func numberOfSections(in tableView: UITableView) -> Int { return 1 @@ -65,48 +57,87 @@ class AcaiaScaleTableVC: UITableViewController { } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - let scale = AcaiaManager.shared().scaleList[indexPath.row] + _activityIndicatorView.isHidden = false + _activityIndicatorView.startAnimating() + let scale = AcaiaManager.shared().scaleList[indexPath.row] scale.connect() - let hud = MBProgressHUD.showAdded(to: view, animated: true) - hud.label.text = String(format:"Connecting to %@", scale.name) - - _timer = Timer.scheduledTimer(timeInterval: 10.0, - target: self, - selector: #selector(onTimer(_:)), - userInfo: nil, - repeats: false) + _timerForConnectTimeOut = Timer.scheduledTimer(timeInterval: 10.0, + target: self, + selector: #selector(_connectTimeOut(_:)), + userInfo: nil, + repeats: false) } // MARK: Private - private var _timer: Timer? = nil + private var _timerForConnectTimeOut: Timer? = nil - @objc private func _scanListChanged(noti: NSNotification) { - tableView.refreshControl?.endRefreshing() - tableView.reloadData() + lazy private var _activityIndicatorView: UIActivityIndicatorView = { + let indicator = UIActivityIndicatorView(style: .large) + indicator.hidesWhenStopped = true + indicator.isHidden = true + + view.addSubview(indicator) + indicator.center = view.center + + return indicator + }() + + private func _setRefreshControl() { + tableView.refreshControl = .init() + tableView.refreshControl?.attributedTitle = .init(string: "Scanning") + tableView.refreshControl?.addAction( + UIAction { _ in AcaiaManager.shared().startScan(0.5) }, + for: .valueChanged + ) } - @objc private func _onConnect() { - MBProgressHUD.hide(for: view, animated: true) + private func _addAcaiaEventsObserver() { + NotificationCenter.default.addObserver(self, + selector: #selector(_didConnected), + name: .init(rawValue: AcaiaScaleDidConnected), + object: nil) + NotificationCenter.default.addObserver(self, + selector: #selector(_didFinishScan), + name: .init(rawValue: AcaiaScaleDidFinishScan), + object: nil) + } + + private func _removeScaleEventObservers() { + NotificationCenter.default.removeObserver(self) + } + + @objc private func _didConnected(notification: NSNotification) { + _activityIndicatorView.stopAnimating() + + _timerForConnectTimeOut?.invalidate() + _timerForConnectTimeOut = nil + navigationController?.popViewController(animated: true) - _timer?.invalidate() - _timer = nil } - @objc private func onFinishScan() { - tableView.refreshControl?.endRefreshing(); - if AcaiaManager.shared().scaleList.count > 0 { - tableView.reloadData() - } + @objc private func _didFinishScan(notification: NSNotification) { + tableView.refreshControl?.endRefreshing() + tableView.reloadData() } - @objc private func onTimer(_ timer: Timer) { - MBProgressHUD.hide(for: view, animated: false) - _timer?.invalidate() - _timer = nil + @objc private func _connectTimeOut(_ timer: Timer) { + _activityIndicatorView.stopAnimating() + + _timerForConnectTimeOut?.invalidate() + _timerForConnectTimeOut = nil + + AcaiaManager.shared().startScan(0.1) + + let alert = UIAlertController(title: nil, + message: "Connect timeout", + preferredStyle: .alert) + alert.addAction(UIAlertAction(title: "Ok", style: .cancel)) + + present(alert, animated: true) } } diff --git a/Example-swift/AcaiaViewController.swift b/Example-swift/AcaiaViewController.swift index 17c7ddf..c1959e7 100644 --- a/Example-swift/AcaiaViewController.swift +++ b/Example-swift/AcaiaViewController.swift @@ -77,20 +77,20 @@ extension AcaiaViewController { private func _addAcaiaEventsObserver() { NotificationCenter.default.addObserver(self, selector: #selector(_onConnect(noti:)), - name: NSNotification.Name(rawValue: AcaiaScaleDidConnected), + name: .init(rawValue: AcaiaScaleDidConnected), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(_onDisconnect(noti:)), - name: NSNotification.Name(rawValue: AcaiaScaleDidDisconnected), + name: .init(rawValue: AcaiaScaleDidDisconnected), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(_onWeight(noti:)), - name: NSNotification.Name(rawValue: AcaiaScaleWeight), + name: .init(rawValue: AcaiaScaleWeight), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(_onTimer(noti:)), - name: NSNotification.Name(rawValue: AcaiaScaleTimer), + name: .init(rawValue: AcaiaScaleTimer), object: nil) } @@ -126,7 +126,7 @@ extension AcaiaViewController { } @objc private func _onTimer(noti: NSNotification) { - guard let time = noti.userInfo?["time"] as? Int else { return } + guard let time = noti.userInfo?[AcaiaScaleUserInfoKeyTimer] as? Int else { return } _timerLabel.text = String(format: "%02d:%02d", time/60, time%60) _isTimerStarted = true; } @@ -155,7 +155,7 @@ extension AcaiaViewController { } @IBAction private func _onBtnPauseTimer() { - if let scale = AcaiaManager.shared().scaleList.first { + if let scale = AcaiaManager.shared().connectedScale { if _isTimerPaused { _isTimerPaused = false scale.startTimer() diff --git a/Example-swift/Base.lproj/Main.storyboard b/Example-swift/Base.lproj/Main.storyboard index ca7d923..81c4a67 100644 --- a/Example-swift/Base.lproj/Main.storyboard +++ b/Example-swift/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -19,7 +19,7 @@ - - - - -