Skip to content

Commit

Permalink
Fix timer issue and update example projects
Browse files Browse the repository at this point in the history
  • Loading branch information
MizukiHo committed May 12, 2022
1 parent 0ca8314 commit f55246a
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 202 deletions.
45 changes: 6 additions & 39 deletions AcaiaExamples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -44,10 +42,9 @@
8E6E186A2339D041005633C5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
8E6E186C2339D041005633C5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Main.storyboard; sourceTree = "<group>"; };
8E6E186D2339D041005633C5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
8E6E186E2339D041005633C5 /* Example-swift test framework.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Example-swift test framework.plist"; sourceTree = "<group>"; };
8E6E186E2339D041005633C5 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8E6E186F2339D041005633C5 /* AcaiaViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AcaiaViewController.swift; sourceTree = "<group>"; };
8E6E18702339D041005633C5 /* AcaiaScaleTableVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AcaiaScaleTableVC.swift; sourceTree = "<group>"; };
8E7924D223447F8C00578CBE /* Example-swift test source.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Example-swift test source.plist"; sourceTree = "<group>"; };
8E7925292344839A00578CBE /* Example-swift test source-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Example-swift test source-Bridging-Header.h"; sourceTree = "<group>"; };
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 = "<group>"; };
Expand All @@ -70,7 +67,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9978998C2828EA1D00352E8B /* MBProgressHUD in Frameworks */,
997899872828E9C600352E8B /* AcaiaSDK.xcframework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -79,7 +75,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9978998A2828EA1400352E8B /* MBProgressHUD in Frameworks */,
997899862828E9C600352E8B /* AcaiaSDK.xcframework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -182,7 +176,6 @@
);
name = "Example-swift";
packageProductDependencies = (
9978998B2828EA1D00352E8B /* MBProgressHUD */,
);
productName = "Example-swift";
productReference = 8E92FF7A2339CA0400BC995C /* Example-swift.app */;
Expand All @@ -202,7 +195,6 @@
);
name = "Example-objc";
packageProductDependencies = (
997899892828EA1400352E8B /* MBProgressHUD */,
);
productName = AcaiaSample;
productReference = 8EDCD15E2339C9190029329D /* Example-objc.app */;
Expand Down Expand Up @@ -237,7 +229,6 @@
);
mainGroup = 8EDCD1552339C9190029329D;
packageReferences = (
997899882828EA1400352E8B /* XCRemoteSwiftPackageReference "MBProgressHUD" */,
);
productRefGroup = 8EDCD15F2339C9190029329D /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */;
}

This file was deleted.

10 changes: 5 additions & 5 deletions AcaiaSDK.xcframework/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@
<array>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>AcaiaSDK.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>AcaiaSDK.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
Expand Down
Binary file modified AcaiaSDK.xcframework/ios-arm64/AcaiaSDK.framework/AcaiaSDK
Binary file not shown.
Binary file modified AcaiaSDK.xcframework/ios-arm64/AcaiaSDK.framework/Info.plist
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</data>
<key>Info.plist</key>
<data>
hYF3vqXUIlBsYmK1xNwNirf8auY=
xuRMmdBXdDFCtnzAGlTBwxtooBI=
</data>
<key>Modules/module.modulemap</key>
<data>
Expand Down
44 changes: 31 additions & 13 deletions Example-objc/AcaiaScaleTableVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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];
Expand All @@ -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
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions Example-objc/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

#import "ViewController.h"
#import <AcaiaSDK/AcaiaSDK.h>
@import AcaiaSDK;


@interface ViewController ()
Expand Down Expand Up @@ -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];
Expand Down
Loading

0 comments on commit f55246a

Please sign in to comment.