gpt4 book ai didi

ios - 我正在尝试使用 WebView 登录页面将控制权传递给另一个 ViewController

转载 作者:行者123 更新时间:2023-12-01 16:28:11 25 4
gpt4 key购买 nike

我正在使用此代码为登录设置 cookie 和 UIWeb-View,如果登录成功已满,但我试图将控制权传递给另一个 UIViewcontroller,但控制权未传递给另一个 View

(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];
});

关于ios - 我正在尝试使用 WebView 登录页面将控制权传递给另一个 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34014748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com