Ios 1密码应用程序扩展无法正常工作
我正在尝试在我的Ios 1密码应用程序扩展无法正常工作,ios,uiwebview,Ios,Uiwebview,我正在尝试在我的UIWebView中实现1Password应用程序扩展。不过我一点运气都没有。下面您可以看到UIWebView的控制器。当我按下Google然后单击1密码按钮时,我可以选择我的Google帐户。但是,一旦我按下它,UIWebView只会重新加载初始页面,其他什么都不会。我做错了什么 #import "LoginWebViewController.h" #import "AFHTTPRequestOperationManager.h" #import "UIImageView+AF
UIWebView
中实现1Password应用程序扩展。不过我一点运气都没有。下面您可以看到UIWebView
的控制器。当我按下Google然后单击1密码按钮时,我可以选择我的Google帐户。但是,一旦我按下它,UIWebView
只会重新加载初始页面,其他什么都不会。我做错了什么
#import "LoginWebViewController.h"
#import "AFHTTPRequestOperationManager.h"
#import "UIImageView+AFNetworking.h"
#import "OnePasswordExtension.h"
#import "UIColor+CustomColors.h"
@interface LoginWebViewController ()
@property (nonatomic, strong) NSString *photoURLString;
@property (weak, nonatomic) IBOutlet UIButton *onepasswordFillButton;
@property (strong, nonatomic) WKWebView *webView;
@end
@implementation LoginWebViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.onepasswordFillButton setHidden:![[OnePasswordExtension sharedExtension] isAppExtensionAvailable]];
}
- (IBAction)fillUsing1Password:(id)sender {
[[OnePasswordExtension sharedExtension] fillLoginIntoWebView:self.webView forViewController:self sender:sender completion:^(BOOL success, NSError *error) {
if (!success) {
NSLog(@"Failed to fill login in webview: <%@>", error);
}
}];
}
- (void)viewWillAppear:(BOOL)animated {
UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.frame = CGRectMake(0, 20, self.view.frame.size.width, 44);
toolbar.barTintColor = [UIColor customBlueColor];
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
// choose whatever width you need instead of 600
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2-40, 0, 80, 25)];
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.text = @"Log in";
label.font = [UIFont boldSystemFontOfSize:20.0];
UIBarButtonItem *toolBarTitle = [[UIBarButtonItem alloc] initWithCustomView:label];
UIBarButtonItem *onepasswordButton = [[UIBarButtonItem alloc] initWithTitle:@"1P"
style:UIBarButtonItemStyleDone target:self
action:@selector(fillUsing1Password:)];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Close"
style:UIBarButtonItemStyleDone target:self
action:@selector(backButtonPressed:)];
NSArray *items = [[NSArray alloc] initWithObjects:doneButton, spacer, toolBarTitle, spacer, onepasswordButton, nil];
[toolbar setItems:items];
self.webView=[[UIWebView alloc]initWithFrame:CGRectMake(0, 24, self.view.frame.size.width, self.view.frame.size.height-24)];
NSString *url=@"https://sandbox.feedly.com/v3/auth/auth?client_id=sandbox&redirect_uri=http://localhost&response_type=code&scope=https%3A%2F%2Fcloud.feedly.com%2Fsubscriptions";
NSURL *nsurl=[NSURL URLWithString:url];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[self.webView loadRequest:nsrequest];
[self.view addSubview:self.webView];
[self.view addSubview:toolbar];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *URLString = [[request URL] absoluteString];
NSString *urlStart = [URLString substringToIndex:23];
if ([urlStart isEqualToString:@"http://localhost/?code="])
{
NSLog(@"Successful login.");
}
}
- (IBAction) backButtonPressed:(id) sender {
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
@end
#导入“LoginWebViewController.h”
#导入“AFHTTPRequestOperationManager.h”
#导入“UIImageView+AFNetworking.h”
#导入“OnePasswordExtension.h”
#导入“UIColor+CustomColors.h”
@接口登录WebViewController()
@属性(非原子,强)NSString*photoURLString;
@属性(弱,非原子)IBUIButton*onepasswordFillButton;
@属性(强,非原子)WKWebView*webView;
@结束
@实现LoginWebViewController
-(无效)viewDidLoad{
[超级视图下载];
//加载视图后执行任何其他设置。
[self.onepasswordFillButton设置隐藏:![[OnePasswordExtension sharedExtension]isAppExtensionAvailable];
}
-(iAction)填写1密码:(id)发件人{
[[OnePasswordExtension sharedExtension]FillLoginTowView:self.webView for ViewController:self发件人:发件人完成:^(布尔成功,N错误*错误){
如果(!成功){
NSLog(@“未能在webview中填写登录信息:”,错误);
}
}];
}
-(无效)视图将显示:(BOOL)动画{
UIToolbar*工具栏=[[UIToolbar alloc]init];
toolbar.frame=CGRectMake(0,20,self.view.frame.size.width,44);
toolbar.barTintColor=[UIColor customBlueColor];
UIBarButtonItem*间隔=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarbuttonSystemFlexibleSpace
目标:零
行动:无];
#定义UIColorFromRGB(RGB值)[UIColor\
带有红色的颜色:((浮动)((RGB值&0xFF0000)>>16))/255.0\
绿色:((浮动)((RGB值&0xFF00)>>8))/255.0\
蓝色:((浮动)(RGB值和0xFF))/255.0 alpha:1.0]
//选择您需要的宽度,而不是600
UILabel*label=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-40,0,80,25)];
label.textAlignment=UITextAlignmentCenter;
label.backgroundColor=[UIColor clearColor];
label.textColor=[UIColor-whiteColor];
label.text=@“登录”;
label.font=[UIFont boldSystemFontOfSize:20.0];
UIBarButtonItem*toolBarTitle=[[UIBarButtonItem alloc]initWithCustomView:label];
UIBarButtonItem*onepasswordButton=[[UIBarButtonItem alloc]initWithTitle:@“1P”
样式:uibarbuttonimstyledone目标:self
操作:@selector(使用1password:)];
UIBarButtonItem*doneButton=[[UIBarButtonItem alloc]initWithTitle:@“关闭”
样式:uibarbuttonimstyledone目标:self
操作:@选择器(按BackButton:)];
NSArray*items=[[NSArray alloc]initWithObjects:doneButton,间隔符,toolBarTitle,间隔符,onepasswordButton,nil];
[工具栏设置项:项];
self.webView=[[UIWebView alloc]initWithFrame:CGRectMake(0,24,self.view.frame.size.width,self.view.frame.size.height-24)];
NSString*url=@”https://sandbox.feedly.com/v3/auth/auth?client_id=sandbox&redirect_uri=http://localhost&response_type=code&scope=https%3A%2F%2Fcloud.feedly.com%2Fsubscriptions";
NSURL*NSURL=[NSURL URLWithString:url];
NSURLRequest*nsrequest=[NSURLRequest requestWithURL:nsurl];
[self.webView加载请求:nsrequest];
[self.view addSubview:self.webView];
[self.view addSubview:工具栏];
}
-(无效)未收到记忆警告{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
-(BOOL)webView:(UIWebView*)webView应加载WithRequest:(NSURLRequest*)请求导航类型:(UIWebViewNavigationType)导航类型{
NSString*URLString=[[请求URL]绝对字符串];
NSString*urlStart=[URLString substringToIndex:23];
如果([urlStart isEqualToString:@]http://localhost/?code="])
{
NSLog(@“成功登录”);
}
}
-(iAction)BackButton按下:(id)发送方{
[self.presentingViewController dismissViewControllerAnimated:YES完成:nil];
}
@结束
我不断地发现这个错误:
Failed to fill login in webview: <Error Domain=OnePasswordExtension Code=0 "1Password Extension was cancelled by the user" UserInfo=0x17427be00 {NSLocalizedDescription=1Password Extension was cancelled by the user}>
未能在webview中填写登录名:
事实证明,问题是我在视图中创建的视图将出现
。扩展是一个覆盖,因此在扩展完成后,视图将出现
我所做的是将其移动到viewDidLoad
。瞧,它起作用了。是否调用了fillUsing1Password:
方法?如果是这样的话,完成块中是否有错误?是的,我用错误更新了问题。