Skip to content

Commit

Permalink
initial device integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Leighton committed Jun 22, 2022
1 parent 5f324bb commit 708096d
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 11 deletions.
3 changes: 2 additions & 1 deletion RNCardConnectReactLibrary.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ Pod::Spec.new do |s|
s.authors = { "Brijesh Singh" => "[email protected]" }
s.platforms = { :ios => "9.0" }
s.source = { :git => "https://github.com/BigRoomStudios/react-native-card-connect.git", :tag => "#{s.version}" }
s.source_files = "ios/*.{h,m}", "ios/BoltMobileSDK.framework/IDTech.bundle"
s.source_files = "ios/*.{h,m}"
s.requires_arc = true
s.dependency "React"
s.ios.vendored_frameworks = "**/ios/BoltMobileSDK.framework"
s.resource = "ios/BoltMobileSDK.framework/IDTech.bundle"
end
6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -452,17 +452,17 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
DoubleConversion: 5805e889d232975c086db112ece9ed034df7a0b2
DoubleConversion: cf9b38bf0b2d048436d9a82ad2abe1404f11e7de
FBLazyVector: c71c5917ec0ad2de41d5d06a5855f6d5eda06971
FBReactNativeSpec: aa8d57969370ad99c59d4cc5a8efb659d1759819
FBReactNativeSpec: d91a9efb848e528726683835cf5cff18ea04e75d
Flipper: d3da1aa199aad94455ae725e9f3aa43f3ec17021
Flipper-DoubleConversion: 38631e41ef4f9b12861c67d17cb5518d06badc41
Flipper-Folly: 755929a4f851b2fb2c347d533a23f191b008554c
Flipper-Glog: 1dfd6abf1e922806c52ceb8701a3599a79a200a6
Flipper-PeerTalk: 116d8f857dc6ef55c7a5a75ea3ceaafe878aadc9
Flipper-RSocket: 127954abe8b162fcaf68d2134d34dc2bd7076154
FlipperKit: 8a20b5c5fcf9436cac58551dc049867247f64b00
glog: 1f3da668190260b06b429bb211bfbee5cd790c28
glog: 73c2498ac6884b13ede40eda8228cb1eee9d9d62
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
OpenSSL-Universal: 1aa4f6a6ee7256b83db99ec1ccdaa80d10f9af9b
RCT-Folly: ec7a233ccc97cc556cf7237f0db1ff65b986f27c
Expand Down
5 changes: 4 additions & 1 deletion example/ios/example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; };
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
7BA65E56286367720038FC02 /* IDTech.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 7BA65E55286367720038FC02 /* IDTech.bundle */; };
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
BD3FB1B8F9F3A2FE46620ECB /* libPods-example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2A06A5054BCED19260BAC52B /* libPods-example.a */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -40,6 +41,7 @@
3DE1DA1E70C59968CF1AAE55 /* Pods-example-exampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-exampleTests.release.xcconfig"; path = "Target Support Files/Pods-example-exampleTests/Pods-example-exampleTests.release.xcconfig"; sourceTree = "<group>"; };
46D3F4AF41B20DF631D38EC1 /* Pods-example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example.debug.xcconfig"; path = "Target Support Files/Pods-example/Pods-example.debug.xcconfig"; sourceTree = "<group>"; };
5C7678136C8222F9677DCF9E /* Pods-example-exampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-exampleTests.debug.xcconfig"; path = "Target Support Files/Pods-example-exampleTests/Pods-example-exampleTests.debug.xcconfig"; sourceTree = "<group>"; };
7BA65E55286367720038FC02 /* IDTech.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; name = IDTech.bundle; path = ../../ios/BoltMobileSDK.framework/IDTech.bundle; sourceTree = "<group>"; };
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = example/LaunchScreen.storyboard; sourceTree = "<group>"; };
9D6EBCE8DE424A1D76CFC2BF /* libPods-example-exampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-example-exampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
A49C25FEF2486DA8EFDB0B02 /* Pods-example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example.release.xcconfig"; path = "Target Support Files/Pods-example/Pods-example.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -116,6 +118,7 @@
83CBB9F61A601CBA00E9B192 = {
isa = PBXGroup;
children = (
7BA65E55286367720038FC02 /* IDTech.bundle */,
13B07FAE1A68108700A75B9A /* example */,
832341AE1AAA6A7D00B99B32 /* Libraries */,
00E356EF1AD99517003FC87E /* exampleTests */,
Expand Down Expand Up @@ -145,7 +148,6 @@
5C7678136C8222F9677DCF9E /* Pods-example-exampleTests.debug.xcconfig */,
3DE1DA1E70C59968CF1AAE55 /* Pods-example-exampleTests.release.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -243,6 +245,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7BA65E56286367720038FC02 /* IDTech.bundle in Resources */,
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */,
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
);
Expand Down
12 changes: 6 additions & 6 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

243 changes: 243 additions & 0 deletions ios/RNCardConnectReactLibrary.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,247 @@ - (dispatch_queue_t)methodQueue
];
}

- (void)swiper:(BMSSwiper *)swiper connectionStateHasChanged:(BMSSwiperConnectionState)state
{
RCTLogInfo(@"swiper connectionStateHasChanged");

// [self sendEventWithName:@"BoltOnSwiperReady"];

// switch (state) {
// case BMSSwiperConnectionStateConnected:
// NSLog(@"Did Connect Swiper");
// self.swiperStatus.text = @"Connected";
// self.connectButton.enabled = NO;
// if (self.communicationAlert)
// {
// if (self.presentedViewController == self.communicationAlert)
// {
// [self.communicationAlert dismissViewControllerAnimated:YES completion:^{
// self.communicationAlert = nil;
// }];
// }
// else
// {
// self.communicationAlert = nil;
// }
// }
// break;
// case BMSSwiperConnectionStateDisconnected:
// NSLog(@"Did Disconnect Swiper");
// self.swiperStatus.text = @"Disconnected";
// self.connectButton.enabled = YES;
// if (self.communicationAlert)
// {
// if (self.presentedViewController == self.communicationAlert)
// {
// [self.communicationAlert dismissViewControllerAnimated:YES completion:^{
// self.communicationAlert = nil;
// }];
// }
// else
// {
// self.communicationAlert = nil;
// }
// }
// break;
// case BMSSwiperConnectionStateConfiguring:
// NSLog(@"Configuring Device");
// self.swiperStatus.text = @"Configuring";
// self.connectButton.enabled = NO;
// [self i_showCommunicationAlertWithMessage:@"Configuring" cancelable:NO];
// break;
// case BMSSwiperConnectionStateConnecting:
// NSLog(@"Will Connect Swiper");
// self.swiperStatus.text = @"Connecting";
// self.connectButton.enabled = NO;
// [self i_showCommunicationAlertWithMessage:@"Connecting" cancelable:NO];
// break;
// case BMSSwiperConnectionStateSearching:
// NSLog(@"Will search for Swiper");
// self.swiperStatus.text = @"Searching";
// self.connectButton.enabled = NO;
// [self i_showCommunicationAlertWithMessage:@"Searching" cancelable:YES];
// break;
// default:
// break;
// }
}

- (void)swiperDidStartCardRead:(BMSSwiper *)swiper
{
RCTLogInfo(@"swiper swiperDidStartCardRead");

[self sendEventWithName:@"BoltOnSwiperReady" body:@{@"test": @"I guess I need a body"}];
// NSLog(@"Card Read Started");
// [self.view endEditing:YES];

// if (self.alert == nil)
// {
// self.alert = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleAlert];
// [self.alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
// self.alert = nil;
// [self.swiper cancelTransaction];
// }]];
// }

// if (self.swipeOnlySwitch.isOn ||
// ((AppDelegate*)[UIApplication sharedApplication].delegate).swiperType == BMSSwiperTypeBBPOS)
// {
// self.alert.message = @"Swipe Card";
// }

// if (!self.presentedViewController)
// {
// [self presentViewController:self.alert animated:YES completion:nil];
// }
// else
// {
// // Delay until alert is dismissed
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// if (!self.presentedViewController)
// {
// [self presentViewController:self.alert animated:YES completion:nil];
// }
// });
// }
}

- (void)swiper:(BMSSwiper *)swiper didGenerateTokenWithAccount:(BMSAccount *)account completion:(void (^)(void))completion
{
RCTLogInfo(@"swiper didGenerateTokenWithAccount");

[self sendEventWithName:@"BoltOnTokenGenerated" body:@{@"token": account.token}];

// [self i_stopActivityIndicator];

// if (self.alert)
// {
// [self.alert dismissViewControllerAnimated:YES completion:^{
// self.alert = nil;
// }];
// }
// else if (self.communicationAlert)
// {
// [self.communicationAlert dismissViewControllerAnimated:YES completion:^{
// self.communicationAlert = nil;
// }];
// }

// if (account)
// {
// UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Token Generated" message:account.token preferredStyle:UIAlertControllerStyleAlert];
// [alert addAction:[UIAlertAction actionWithTitle:@"Retry" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// completion();
// }]];
// [alert addAction:[UIAlertAction actionWithTitle:@"Done" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
// self.restartReaderBlock = completion;
// self.restartReaderButton.enabled = YES;
// }]];
// [self presentViewController:alert animated:YES completion:nil];
// }
// else
// {
// UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Error" message:@"An unknown error" preferredStyle:UIAlertControllerStyleAlert];
// [alert addAction:[UIAlertAction actionWithTitle:@"Retry" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// completion();
// }]];
// [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
// self.restartReaderBlock = completion;
// self.restartReaderButton.enabled = YES;
// }]];
// [self presentViewController:alert animated:YES completion:nil];
// }
}

- (void)swiper:(BMSSwiper *)swiper didFailWithError:(NSError *)error completion:(void (^)(void))completion
{
RCTLogInfo(@"swiper didFailWithError");
RCTLogInfo(error.localizedDescription);

[self sendEventWithName:@"BoltOnSwipeError" body:@{@"error": error.localizedDescription}];

// [self i_stopActivityIndicator];

// if (self.alert)
// {
// [self.alert dismissViewControllerAnimated:YES completion:^{
// self.alert = nil;
// }];
// }
// else if (self.communicationAlert)
// {
// [self.communicationAlert dismissViewControllerAnimated:YES completion:^{
// self.communicationAlert = nil;
// }];
// }

// NSMutableString *errorMessage = [[NSMutableString alloc] initWithFormat:@"An error occured:\n%@",error.localizedDescription];

// if ([error.userInfo valueForKey:@"firmwareVersion"])
// {
// [errorMessage appendFormat:@"\n\n%@", [error.userInfo valueForKey:@"firmwareVersion"]];
// }

// UIAlertController *controller = [UIAlertController alertControllerWithTitle:@""
// message:errorMessage
// preferredStyle:UIAlertControllerStyleAlert];
// [controller addAction:[UIAlertAction actionWithTitle:@"Retry" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
// completion();
// }]];
// [controller addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
// self.restartReaderBlock = completion;
// self.restartReaderButton.enabled = YES;
// }]];
// [self presentViewController:controller animated:YES completion:nil];
}

- (void)swiper:(BMSSwiperController*)swiper foundDevices:(NSArray*)devices
{
RCTLogInfo(@"swiper foundDevices");

BMSDevice *device = [devices objectAtIndex:0];
// int value = returnedObject.aVariable;
[self sendEventWithName:@"BoltDeviceFound" body:@{@"macAddress": device.uuid, @"name": device.name}];
}

- (void)swiper:(BMSSwiperController*)swiper displayMessage:(NSString*)message canCancel:(BOOL)cancelable
{
RCTLogInfo(@"swiper displayMessage");
// if (self.alert == nil)
// {
// self.alert = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleAlert];
// }

// self.alert.message = message;

// if (cancelable &&
// self.alert.actions.count == 0)
// {
// [self.alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
// self.alert = nil;
// [self.swiper cancelTransaction];
// }]];
// }
// else if (!cancelable &&
// self.alert.actions.count > 0)
// {
// for (UIAlertAction *action in self.alert.actions)
// {
// action.enabled = NO;
// }
// }

// if (!self.presentedViewController)
// {
// [self presentViewController:self.alert animated:YES completion:nil];
// }
}

- (void)swiper:(BMSSwiperController *)swiper configurationProgress:(float)progress
{
RCTLogInfo(@"swiper configurationProgress");
// [self i_showCommunicationAlertWithMessage:[NSString stringWithFormat:@"Configuring: %.0f%%",progress*100]
// cancelable:NO];
}

@end

0 comments on commit 708096d

Please sign in to comment.