Ios 我正在尝试使用UIWeb视图登录页将控制传递给另一个UIViewController
我使用这段代码为登录设置cookie和UIWeb视图,如果登录成功,但控制未传递到另一个视图,我将尝试将控制传递给另一个UIViewcontrollerIos 我正在尝试使用UIWeb视图登录页将控制传递给另一个UIViewController,ios,objective-c,cookies,uiwebview,Ios,Objective C,Cookies,Uiwebview,我使用这段代码为登录设置cookie和UIWeb视图,如果登录成功,但控制未传递到另一个视图,我将尝试将控制传递给另一个UIViewcontroller (void)viewDidLoad { [super viewDidLoad]; AppDelegate *app = [[UIApplication sharedApplication]delegate]; NSString *urlString = @"http://streamtvbox.com/site/wp-login
(void)viewDidLoad
{
[super viewDidLoad];
AppDelegate *app = [[UIApplication sharedApplication]delegate];
NSString *urlString = @"http://streamtvbox.com/site/wp-login.php";
NSURL *url = [NSURL URLWithString:urlString];
NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPShouldHandleCookies:YES];
[self addCookies:cookies forRequest:request];
[self.webView loadRequest:request];
[self Login];
}
(void)addCookies:(NSArray *)cookies forRequest:(NSMutableURLRequest *)request
{
if ([cookies count] == 0)
{
NSString *cookieHeader = nil;
AppDelegate *app = [[UIApplication sharedApplication]delegate];
NSHTTPCookie *cooki;
app.cookie = cooki;
for (cooki in cookies)
{
if (!cookieHeader)
{
cookieHeader = [NSString stringWithFormat: @"%@=%@",[app.cookie name],[app.cookie value]];
}
else
{
cookieHeader = [NSString stringWithFormat: @"%@; %@=%@",cookieHeader,[app.cookie name],[app.cookie value]];
}
}
if (cookieHeader)
{
[request setValue:cookieHeader forHTTPHeaderField:@"Cookie"];
}
}
}
-(void)Login
{
Service *srv=[[Service alloc]init];
NSString *str=@"http://streamtvbox.com/site/api/matrix/";
NSString *method=@"channels";
NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
[srv postToURL:str withMethod:method andParams:dict completion:^(BOOL success, NSDictionary *responseObj)
{
if (success) {
TabBarController *TabBar = [self.storyboard instantiateViewControllerWithIdentifier:@"TabBar"];
[self.navigationController pushViewController:TabBar animated:YES];
}
else
{
[self Login1];
}
}];
}
视图相关活动必须在主线程中完成。像这样更改代码
dispatch_async(dispatch_get_main_queue(), ^
{
TabBarController *TabBar = [self.storyboard instantiateViewControllerWithIdentifier:@"TabBar"];
[self.navigationController pushViewController:TabBar animated:YES];
});
您好,我正在尝试调用在UIWebview中完成的视图登录,所以我在哪里调用此方法?