Ios 网页加载完成后读取数据

Ios 网页加载完成后读取数据,ios,objective-c,http,connection,Ios,Objective C,Http,Connection,我在iOS上做了一个登录方法,通过url向PHP页面发送GET请求,当我尝试读取网站的输出时,数据在PHP完成mysql查询之前被读取,我想知道是否有任何方法可以等到网页完全加载完毕后再从中读取数据 代码: 我会尝试通过sendAsynchronousRequest使用NSURLConnection,就像这样 NSOperationQueue *myQueue = [[NSOperationQueue alloc]init]; [NSURLConnection sendAsynchron

我在iOS上做了一个登录方法,通过url向PHP页面发送GET请求,当我尝试读取网站的输出时,数据在PHP完成mysql查询之前被读取,我想知道是否有任何方法可以等到网页完全加载完毕后再从中读取数据 代码:


我会尝试通过
sendAsynchronousRequest
使用
NSURLConnection
,就像这样

NSOperationQueue *myQueue = [[NSOperationQueue alloc]init];
    [NSURLConnection sendAsynchronousRequest:request queue:myQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
        //do something
    }];
当启动处理程序块时,您就拥有了自己的内容,这一点基本上是不言自明的

另一个选项是调用
NSURLConnectionDataDelegate
。当你调用你的URL时,它会触发一些方法,让你知道事情何时完成

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    //Fired on error
}

- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
{
    //Fired First
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    //Fired Second
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    //Fired Third
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    //Fired Fourth
}
使用委托方法,您可能希望利用
didReceiveData
,以便您的数据就在那里。祝你好运

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    //Fired on error
}

- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
{
    //Fired First
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    //Fired Second
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    //Fired Third
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    //Fired Fourth
}