// // UIViewController+Wallet.m // Unity-iPhone // // Created by zhl on 2022/9/1. // #import "UIViewController+Wallet.h" #import "QRCodeReaderViewController.h" #import "QRCodeReader.h" #import "QRCodeReaderDelegate.h" @implementation UIViewController (Wallet) +(void)toWallet:(NSString *)url{ UIApplication *app = [UIApplication sharedApplication]; [app openURL:[NSURL URLWithString:url]]; } -(void)scanQRCode:(NSString *)title{ NSLog(@"scanQRCode: %@", title); if ([QRCodeReader supportsMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]]) { static QRCodeReaderViewController *vc = nil; static dispatch_once_t onceToken; // dispatch_once(&onceToken, ^{ // // }); dispatch_async(dispatch_get_main_queue(), ^{ // if we are active again, we don't need to do this anymore QRCodeReader *reader = [QRCodeReader readerWithMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]]; vc = [QRCodeReaderViewController readerWithCancelButtonTitle:@"Cancel" codeReader:reader startScanningAtLoad:YES showSwitchCameraButton:YES showTorchButton:YES]; vc.modalPresentationStyle = UIModalPresentationFormSheet; [vc setCompletionWithBlock:^(NSString *resultAsString) { NSLog(@"Completion with result: %@", resultAsString); [self dismissViewControllerAnimated:YES completion:^{ }]; }]; [self presentViewController:vc animated:YES completion:NULL]; }); } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Reader not supported by the current device" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } } @end