diff --git a/Classes_cocos/UIViewController+QR.mm b/Classes_cocos/UIViewController+QR.mm index b147bef..bff4bb0 100644 --- a/Classes_cocos/UIViewController+QR.mm +++ b/Classes_cocos/UIViewController+QR.mm @@ -44,32 +44,32 @@ -(void)loadRestoreKey:(NSString *)funid oid:(NSString *) oid{ NSLog(@"loadRestoreKey::funid: %@, oid:%@", funid, oid); -// if ([NSThread isMainThread]) { -// -// } + // if ([NSThread isMainThread]) { + // + // } dispatch_async(dispatch_get_main_queue(), ^{ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Tips" message:@"In order to restore recovery key, please Scan QRCode or Pick from Photo Library." preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"Cancel" - style:UIAlertActionStyleCancel - handler: ^(UIAlertAction *action){ - NSLog(@"alert cancel pressed"); + style:UIAlertActionStyleCancel + handler: ^(UIAlertAction *action){ + NSLog(@"alert cancel pressed"); }]; UIAlertAction *scanAction = [UIAlertAction actionWithTitle:@"Scan" - style:UIAlertActionStyleDefault - handler: ^(UIAlertAction *action){ - NSLog(@"scan pressed"); + style:UIAlertActionStyleDefault + handler: ^(UIAlertAction *action){ + NSLog(@"scan pressed"); [self scanQRCode:funid title: @"" ]; }]; UIAlertAction *photoAction = [UIAlertAction actionWithTitle:@"Photo" - style:UIAlertActionStyleDefault - handler: ^(UIAlertAction *action){ - NSLog(@"photo pressed"); + style:UIAlertActionStyleDefault + handler: ^(UIAlertAction *action){ + NSLog(@"photo pressed"); [self openLocalPhotoAlbum]; - + }]; [alertController addAction:actionCancel]; [alertController addAction:scanAction]; @@ -81,51 +81,51 @@ -(void)startScanQRCode:(NSString *)funid title:(NSString *) title{ std::string sfunid = std::string([funid UTF8String], [funid lengthOfBytesUsingEncoding:NSUTF8StringEncoding]); if ([QRCodeReader supportsMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]]) { - static QRCodeReaderViewController *vc = nil; - static dispatch_once_t onceToken; - - dispatch_async(dispatch_get_main_queue(), ^{ - // if we are active again, we don't need to do this anymore - if (vc == nil) { - QRCodeReader *reader = [QRCodeReader readerWithMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]]; - vc = [QRCodeReaderViewController readerWithCancelButtonTitle:@"Cancel" codeReader:reader startScanningAtLoad:YES showSwitchCameraButton:YES showTorchButton:YES]; - vc.modalPresentationStyle = UIModalPresentationFormSheet; + static QRCodeReaderViewController *vc = nil; + static dispatch_once_t onceToken; + + dispatch_async(dispatch_get_main_queue(), ^{ + // if we are active again, we don't need to do this anymore + if (vc == nil) { + 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:^{ + + NSString *result; + if (resultAsString.length > 0) { + result = [NSString stringWithFormat:@"{errcode: 0, data: '%@'}", resultAsString]; + } else { + result = [NSString stringWithFormat:@"{errcode: 1, errmsg: 'cancel'}"]; } - - [vc setCompletionWithBlock:^(NSString *resultAsString) { - NSLog(@"Completion with result: %@", resultAsString); - [self dismissViewControllerAnimated:YES completion:^{ - - NSString *result; - if (resultAsString.length > 0) { - result = [NSString stringWithFormat:@"{errcode: 0, data: '%@'}", resultAsString]; - } else { - result = [NSString stringWithFormat:@"{errcode: 1, errmsg: 'cancel'}"]; - } - std::string sresult = std::string([result UTF8String], [result lengthOfBytesUsingEncoding:NSUTF8StringEncoding]); -// WalletEvent::Emit(sfunid.c_str(), sresult.c_str()); - }]; - }]; - [self presentViewController:vc animated:YES completion:NULL]; - }); + std::string sresult = std::string([result UTF8String], [result lengthOfBytesUsingEncoding:NSUTF8StringEncoding]); + // WalletEvent::Emit(sfunid.c_str(), sresult.c_str()); + }]; + }]; + [self presentViewController:vc animated:YES completion:NULL]; + }); } } -(void)scanQRCode:(NSString *)funid title:(NSString *) title{ NSLog(@"scanQRCode:: funId: %@ title: %@", funid, title); -// [self openLocalPhotoAlbum]; -// [self signWithApple]; + // [self openLocalPhotoAlbum]; + // [self signWithApple]; __weak __typeof(self) weakSelf = self; [LBXPermission authorizeWithType:LBXPermissionType_Camera completion:^(BOOL granted, BOOL firstTime) { - if (granted) { - [weakSelf startScanQRCode:funid title:title]; - } - else if(!firstTime) - { - [LBXPermissionSetting showAlertToDislayPrivacySettingWithTitle:@"Error" msg:@"The camera is need to scan QR codes" cancel:@"Cancel" setting:@"Setting" ]; - } + if (granted) { + [weakSelf startScanQRCode:funid title:title]; + } + else if(!firstTime) + { + [LBXPermissionSetting showAlertToDislayPrivacySettingWithTitle:@"Error" msg:@"The camera is need to scan QR codes" cancel:@"Cancel" setting:@"Setting" ]; + } }]; } @@ -135,13 +135,13 @@ __weak __typeof(self) weakSelf = self; dispatch_async(dispatch_get_main_queue(), ^{ [LBXPermission authorizeWithType:LBXPermissionType_Photos completion:^(BOOL granted, BOOL firstTime) { - if (granted) { - [weakSelf openLocalPhoto]; - } - else if (!firstTime ) - { - [LBXPermissionSetting showAlertToDislayPrivacySettingWithTitle:@"Error" msg:@"The Photo Library is need to restore recovery key." cancel:@"Cancel" setting:@"Setting"]; - } + if (granted) { + [weakSelf openLocalPhoto]; + } + else if (!firstTime ) + { + [LBXPermissionSetting showAlertToDislayPrivacySettingWithTitle:@"Error" msg:@"The Photo Library is need to restore recovery key." cancel:@"Cancel" setting:@"Setting"]; + } }]; }); } @@ -160,16 +160,16 @@ // crash on some mobile picker.allowsEditing = NO; - + [self presentViewController:picker animated:YES completion:nil]; } #pragma mark- - UIImagePickerControllerDelegate -(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { - [picker dismissViewControllerAnimated:YES completion:^{ - - [self handPhotoDidFinishPickingMediaWithInfo:info]; - }]; + [picker dismissViewControllerAnimated:YES completion:^{ + + [self handPhotoDidFinishPickingMediaWithInfo:info]; + }]; } - (void)handPhotoDidFinishPickingMediaWithInfo:(NSDictionary *)info @@ -177,13 +177,13 @@ __block UIImage* image = [info objectForKey:UIImagePickerControllerEditedImage]; if (!image){ - image = [info objectForKey:UIImagePickerControllerOriginalImage]; + image = [info objectForKey:UIImagePickerControllerOriginalImage]; } if (@available(iOS 8.0, *)) { - __weak __typeof(self) weakSelf = self; - [LBXScanNative recognizeImage:image success:^(NSArray *array) { - [weakSelf scanResultWithArray:array]; - }]; + __weak __typeof(self) weakSelf = self; + [LBXScanNative recognizeImage:image success:^(NSArray *array) { + [weakSelf scanResultWithArray:array]; + }]; }else{ NSLog(@"native低于ios8.0不支持识别图片"); } @@ -191,22 +191,22 @@ - (void)scanResultWithArray:(NSArray*)array { - if (!array || array.count < 1) - { - NSLog(@"error scan photo"); - return; - } - - for (LBXScanResult *result in array) { - NSLog(@"scanResult:%@",result.strScanned); - } - - if (!array[0].strScanned || [array[0].strScanned isEqualToString:@""] ) { - NSLog(@"识别失败了"); - return; - } - LBXScanResult *scanResult = array[0]; - + if (!array || array.count < 1) + { + NSLog(@"error scan photo"); + return; + } + + for (LBXScanResult *result in array) { + NSLog(@"scanResult:%@",result.strScanned); + } + + if (!array[0].strScanned || [array[0].strScanned isEqualToString:@""] ) { + NSLog(@"识别失败了"); + return; + } + LBXScanResult *scanResult = array[0]; + } @end diff --git a/Classes_cocos/UIViewController+Wallet.mm b/Classes_cocos/UIViewController+Wallet.mm index 357c61c..83963f3 100644 --- a/Classes_cocos/UIViewController+Wallet.mm +++ b/Classes_cocos/UIViewController+Wallet.mm @@ -25,8 +25,8 @@ static NSString * const kClientID = @implementation UIViewController (Wallet) +(void)toWallet:(NSString *)url{ - UIApplication *app = [UIApplication sharedApplication]; - [app openURL:[NSURL URLWithString:url]]; + UIApplication *app = [UIApplication sharedApplication]; + [app openURL:[NSURL URLWithString:url]]; } @@ -45,74 +45,74 @@ static NSString * const kClientID = -(void)signToGoogle:(NSString *) funid { - GIDConfiguration *_configuration = [[GIDConfiguration alloc] initWithClientID:kClientID]; - [GIDSignIn.sharedInstance signInWithConfiguration:_configuration - presentingViewController:self - completion:^(GIDGoogleUser *user, NSError *error) { - if (error) { - NSLog(@"Status: Authentication error: %@", error); - } - [self refreshUserInfo]; - [self refreshTokenID: user funid:funid]; - }]; + GIDConfiguration *_configuration = [[GIDConfiguration alloc] initWithClientID:kClientID]; + [GIDSignIn.sharedInstance signInWithConfiguration:_configuration + presentingViewController:self + completion:^(GIDGoogleUser *user, NSError *error) { + if (error) { + NSLog(@"Status: Authentication error: %@", error); + } + [self refreshUserInfo]; + [self refreshTokenID: user funid:funid]; + }]; } -(void) refreshTokenID:(GIDGoogleUser *)user funid:(NSString*) funid{ - [user.authentication doWithFreshTokens:^(GIDAuthentication * _Nullable authentication, - NSError * _Nullable error) { - if (error) { return; } - if (authentication == nil) { return; } - - NSString *idToken = authentication.idToken; - // Send ID token to backend (example below). - NSLog(@"idToken: %@", idToken); - std::string methodName = "nativeCallBack"; - NSString *paramStr = [NSString stringWithFormat:@"{\"errcode\": 0, \"data\": \"%@\"}", idToken]; - std::string sfunid = std::string([funid UTF8String], [funid lengthOfBytesUsingEncoding:NSUTF8StringEncoding]); - std::string sparam = std::string([paramStr UTF8String], [paramStr lengthOfBytesUsingEncoding:NSUTF8StringEncoding]); - cocos2d::nativeCallBack(sfunid.c_str(), methodName.c_str(), sparam.c_str()); - }]; + [user.authentication doWithFreshTokens:^(GIDAuthentication * _Nullable authentication, + NSError * _Nullable error) { + if (error) { return; } + if (authentication == nil) { return; } + + NSString *idToken = authentication.idToken; + // Send ID token to backend (example below). + NSLog(@"idToken: %@", idToken); + std::string methodName = "nativeCallBack"; + NSString *paramStr = [NSString stringWithFormat:@"{\"errcode\": 0, \"data\": \"%@\"}", idToken]; + std::string sfunid = std::string([funid UTF8String], [funid lengthOfBytesUsingEncoding:NSUTF8StringEncoding]); + std::string sparam = std::string([paramStr UTF8String], [paramStr lengthOfBytesUsingEncoding:NSUTF8StringEncoding]); + cocos2d::nativeCallBack(sfunid.c_str(), methodName.c_str(), sparam.c_str()); + }]; } -(void)signWithGoogle:(NSString *)funid { - [GIDSignIn.sharedInstance restorePreviousSignInWithCompletion:^(GIDGoogleUser * _Nullable user, - NSError * _Nullable error) { - if (error) { - // Show the app's signed-out state. - [self signToGoogle: funid]; - } else { - // Show the app's signed-in state. - [self refreshTokenID: user funid:funid]; - } - }]; - + [GIDSignIn.sharedInstance restorePreviousSignInWithCompletion:^(GIDGoogleUser * _Nullable user, + NSError * _Nullable error) { + if (error) { + // Show the app's signed-out state. + [self signToGoogle: funid]; + } else { + // Show the app's signed-in state. + [self refreshTokenID: user funid:funid]; + } + }]; + } -(void)signOutGoogle:(NSString *)funid { - [GIDSignIn.sharedInstance signOut]; + [GIDSignIn.sharedInstance signOut]; } - (void)reportAuthStatus { - GIDGoogleUser *googleUser = [GIDSignIn.sharedInstance currentUser]; - if (googleUser.authentication) { - NSLog(@"Status: Authenticated"); - } else { - // To authenticate, use Google Sign-In button. - NSLog(@"Status: Not authenticated"); - } - - [self refreshUserInfo]; + GIDGoogleUser *googleUser = [GIDSignIn.sharedInstance currentUser]; + if (googleUser.authentication) { + NSLog(@"Status: Authenticated"); + } else { + // To authenticate, use Google Sign-In button. + NSLog(@"Status: Not authenticated"); + } + + [self refreshUserInfo]; } - (void)refreshUserInfo { - if (GIDSignIn.sharedInstance.currentUser.authentication == nil) { - return; - } - NSLog(@"email: %@", GIDSignIn.sharedInstance.currentUser.profile.email); - NSLog(@"username: %@", GIDSignIn.sharedInstance.currentUser.profile.name); - NSLog(@"userid: %@", GIDSignIn.sharedInstance.currentUser.userID); - NSLog(@"givenName: %@", GIDSignIn.sharedInstance.currentUser.profile.givenName); - NSLog(@"familyName: %@", GIDSignIn.sharedInstance.currentUser.profile.familyName); - NSLog(@"hostedDomain: %@", GIDSignIn.sharedInstance.currentUser.hostedDomain); + if (GIDSignIn.sharedInstance.currentUser.authentication == nil) { + return; + } + NSLog(@"email: %@", GIDSignIn.sharedInstance.currentUser.profile.email); + NSLog(@"username: %@", GIDSignIn.sharedInstance.currentUser.profile.name); + NSLog(@"userid: %@", GIDSignIn.sharedInstance.currentUser.userID); + NSLog(@"givenName: %@", GIDSignIn.sharedInstance.currentUser.profile.givenName); + NSLog(@"familyName: %@", GIDSignIn.sharedInstance.currentUser.profile.familyName); + NSLog(@"hostedDomain: %@", GIDSignIn.sharedInstance.currentUser.hostedDomain); } #pragma mark- - Sign In With Apple @@ -130,63 +130,63 @@ static NSString * const kClientID = } - (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization API_AVAILABLE(ios(13.0)) { - if ([authorization.credential isKindOfClass:[ASAuthorizationAppleIDCredential class]]) { - // 用户登录使用ASAuthorizationAppleIDCredential - ASAuthorizationAppleIDCredential *credential = authorization.credential; - NSString *user = credential.user; - NSData *identityToken = credential.identityToken; - NSLog(@"fullName - %@",credential.fullName); - //授权成功后,你可以拿到苹果返回的全部数据,根据需要和后台交互。 - NSLog(@"user - %@ %@",user,identityToken); - //保存apple返回的唯一标识符 - [[NSUserDefaults standardUserDefaults] setObject:user forKey:@"userIdentifier"]; - [[NSUserDefaults standardUserDefaults] synchronize]; - } else if ([authorization.credential isKindOfClass:[ASPasswordCredential class]]) { - // 用户登录使用现有的密码凭证 - ASPasswordCredential *psdCredential = authorization.credential; - // 密码凭证对象的用户标识 用户的唯一标识 - NSString *user = psdCredential.user; - NSString *psd = psdCredential.password; - NSLog(@"psduser - %@ %@",psd,user); - } else { - NSLog(@"授权信息不符"); - } + if ([authorization.credential isKindOfClass:[ASAuthorizationAppleIDCredential class]]) { + // 用户登录使用ASAuthorizationAppleIDCredential + ASAuthorizationAppleIDCredential *credential = authorization.credential; + NSString *user = credential.user; + NSData *identityToken = credential.identityToken; + NSLog(@"fullName - %@",credential.fullName); + //授权成功后,你可以拿到苹果返回的全部数据,根据需要和后台交互。 + NSLog(@"user - %@ %@",user,identityToken); + //保存apple返回的唯一标识符 + [[NSUserDefaults standardUserDefaults] setObject:user forKey:@"userIdentifier"]; + [[NSUserDefaults standardUserDefaults] synchronize]; + } else if ([authorization.credential isKindOfClass:[ASPasswordCredential class]]) { + // 用户登录使用现有的密码凭证 + ASPasswordCredential *psdCredential = authorization.credential; + // 密码凭证对象的用户标识 用户的唯一标识 + NSString *user = psdCredential.user; + NSString *psd = psdCredential.password; + NSLog(@"psduser - %@ %@",psd,user); + } else { + NSLog(@"授权信息不符"); + } } #pragma mark - 授权回调失败 - (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithError:(NSError *)error API_AVAILABLE(ios(13.0)){ - - NSLog(@"错误信息:%@", error); - NSString *errorMsg; - switch (error.code) { - case ASAuthorizationErrorCanceled: - errorMsg = @"用户取消了授权请求"; - NSLog(@"errorMsg - %@",errorMsg); - break; - - case ASAuthorizationErrorFailed: - errorMsg = @"授权请求失败"; - NSLog(@"errorMsg - %@",errorMsg); - break; - - case ASAuthorizationErrorInvalidResponse: - errorMsg = @"授权请求响应无效"; - NSLog(@"errorMsg - %@",errorMsg); - break; - - case ASAuthorizationErrorNotHandled: - errorMsg = @"未能处理授权请求"; - NSLog(@"errorMsg - %@",errorMsg); - break; - - case ASAuthorizationErrorUnknown: - errorMsg = @"授权请求失败未知原因"; - NSLog(@"errorMsg - %@",errorMsg); - break; - - default: - break; - } + + NSLog(@"错误信息:%@", error); + NSString *errorMsg; + switch (error.code) { + case ASAuthorizationErrorCanceled: + errorMsg = @"用户取消了授权请求"; + NSLog(@"errorMsg - %@",errorMsg); + break; + + case ASAuthorizationErrorFailed: + errorMsg = @"授权请求失败"; + NSLog(@"errorMsg - %@",errorMsg); + break; + + case ASAuthorizationErrorInvalidResponse: + errorMsg = @"授权请求响应无效"; + NSLog(@"errorMsg - %@",errorMsg); + break; + + case ASAuthorizationErrorNotHandled: + errorMsg = @"未能处理授权请求"; + NSLog(@"errorMsg - %@",errorMsg); + break; + + case ASAuthorizationErrorUnknown: + errorMsg = @"授权请求失败未知原因"; + NSLog(@"errorMsg - %@",errorMsg); + break; + + default: + break; + } } diff --git a/Unity-iPhone.xcworkspace/xcuserdata/zhl.xcuserdatad/UserInterfaceState.xcuserstate b/Unity-iPhone.xcworkspace/xcuserdata/zhl.xcuserdatad/UserInterfaceState.xcuserstate index b6540c2..300a279 100644 Binary files a/Unity-iPhone.xcworkspace/xcuserdata/zhl.xcuserdatad/UserInterfaceState.xcuserstate and b/Unity-iPhone.xcworkspace/xcuserdata/zhl.xcuserdatad/UserInterfaceState.xcuserstate differ