在iOS上自动启动Google Authenticator应用程序
在iOS上启动Google Authenticator有没有受支持的方法 我想让客户在将其粘贴回我的应用程序之前更容易打开应用程序并复制基于时间的代码 根据经验,我发现这个(Swift)代码将启动应用程序:在iOS上自动启动Google Authenticator应用程序,ios,google-authenticator,Ios,Google Authenticator,在iOS上启动Google Authenticator有没有受支持的方法 我想让客户在将其粘贴回我的应用程序之前更容易打开应用程序并复制基于时间的代码 根据经验,我发现这个(Swift)代码将启动应用程序: UIApplication.sharedApplication().openURL(NSURL(string: "otpauth://")!) …但我想知道是否有更好的、受支持的方法 具体来说,otpauth://协议是否支持无参数启动应用程序?查看应用程序的Git repo,他们似乎已经
UIApplication.sharedApplication().openURL(NSURL(string: "otpauth://")!)
…但我想知道是否有更好的、受支持的方法
具体来说,otpauth://协议是否支持无参数启动应用程序?查看应用程序的Git repo,他们似乎已经为bot
otpauth
和totp
注册了自定义URL方案
这里呢
以下是关于如何准确构建url的文档:
在正确地构建它们并将应用程序和Google Authenticator应用程序放在同一台设备上之后,您只需进行测试。Objective C
if ([[[notification realRequestResults] valueForKey:@"action"] isEqualToString:@"2FA"]) {
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Two Factor Authentication"
message:@"Please, enter your Google Authenticator 2FA Token."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"Confirm Token"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
@try {
NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:
[userName text], @"loginName",
[passwordField text], @"password",
@"false", @"rememberMe",
[[alert textFields][0] text], @"tfa",
nil];
[self callWebserviceForIdentifier:AuthRequestInternalLogin
withParameters:parameters
onSuccessSelector:@selector(loginSuccessfulAgain:)
onFailureSelector:@selector(loginFailedAgain:)];
} @catch (NSException *exception) {
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"login"
message:[NSString stringWithFormat:@"%@", exception.description]
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[alert addAction:defaultAction];
} @finally {
}
}];
[alert addAction:defaultAction];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.delegate = self;
textField.placeholder = [NSMutableString stringWithString:@"Enter your 2FA token"];
textField.keyboardType = UIKeyboardTypeNumberPad;
textField.font = [UIFont systemFontOfSize:16.0];
textField.textAlignment = NSTextAlignmentCenter;
textField.textColor = UIColor.blackColor;
UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
[addButton setImage:[UIImage imageNamed:@"authenticator.png"] forState:UIControlStateNormal];
[addButton addTarget:self action:@selector(authenticatorBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
textField.rightViewMode = UITextFieldViewModeAlways;
textField.rightView = addButton;
}];
[self presentViewController:alert animated:YES completion:nil];
}
else {
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Warning"
message:@"Invalid Credentials. Please try again."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
[self stopAnimation];
}
}
-(IBAction)authenticatorBtnClicked:(id)sender{
NSString *AppStoreURL = @"https://apps.apple.com/in/app/google-authenticator/id388497605";
NSString *customAppURL = @"otpauth://";
BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:customAppURL]];
NSString *url = canOpenURL ? customAppURL : AppStoreURL;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:URL]];
}
在Info.plist文件中
我很确定你应该这样做。谢谢@ILikeTau你有任何内部信息或证据证明这是正确的吗?。记得检查你是否可以用
canOpenURL()
@ILikeTau打开URL。我已经对问题做了一些修改。我知道openURL和canOpenURL是启动其他应用程序的标准机制。但我想知道,不带参数的otpauth://协议作为启动应用程序的一种方式是受支持的。可能会有帮助