Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用NSURLSession的Http/2服务器推送_Ios_Objective C_Nsurlsession_Http2 - Fatal编程技术网

Ios 使用NSURLSession的Http/2服务器推送

Ios 使用NSURLSession的Http/2服务器推送,ios,objective-c,nsurlsession,http2,Ios,Objective C,Nsurlsession,Http2,我已经使用iOS9的NSURLSession实现了一个与http2通信的程序,它可以在http2中与我的服务器通信。 但是,我在接收方面遇到了问题。 我发现他们的设置中的ENABLE_PUSH值为0,并且在接收服务器PUSH-in NSURLSession中没有委托 ・我认为NSURLSession不支持服务器推送。是这样吗 ・如果它支持服务器推送,如何使用 /** It WORKS for post data and get response. I don't know the code sh

我已经使用iOS9的NSURLSession实现了一个与http2通信的程序,它可以在http2中与我的服务器通信。 但是,我在接收方面遇到了问题。 我发现他们的设置中的ENABLE_PUSH值为0,并且在接收服务器PUSH-in NSURLSession中没有委托

・我认为NSURLSession不支持服务器推送。是这样吗

・如果它支持服务器推送,如何使用

/**
It WORKS for post data and get response.
I don't know the code should be added here 
in order to get the server_push.
I suspect that NSURLSession itself cannot receive the server_push(;_;)
**/
- (void) postData
{
     NSString *urlstr = self.urlArea.text;
     NSURL * url = [NSURL URLWithString:urlstr];
     NSDictionary *params = @{@"data":@""};
    //json to query
    NSData *query = [self buildQueryWithDictionary: params];

    //make request
    NSMutableURLRequest *request = [NSMutableURLRequest
                                requestWithURL:url
                                cachePolicy: NSURLRequestReloadIgnoringCacheData
                                timeoutInterval: 10.0];
    [request setHTTPMethod: @"POST"];
    [request setHTTPBody: query];

    //prepare session
    NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[NSOperationQueue mainQueue]];

    //resume
     [[session dataTaskWithRequest: request  completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
    {
        if (response && ! error) {
             NSLog(@"Data: %@", [[NSString alloc] initWithData: data  encoding: NSUTF8StringEncoding]);
        }else {
            NSLog(@"ERR: %@", error);
        }
    }] resume];
}
我读到:

HTTP2推送机制不是一种通用的服务器推送机制,如 websocket或服务器已发送事件

它是为特定的HTTP会话优化而设计的。 特别是当客户端请求资源(例如index.html)时 服务器可以猜测它下一步将请求一堆 相关资源(如theme.css、jquery.js、logo.png等) 通常,一个网页可以有10个这样的相关请求

在HTTP/1.1中,服务器必须等到客户端实际发送 请求这些相关资源,然后客户端将受到限制 通过连接,一次只要求大约6个。因此,它可能需要 在需要所有相关资源之前进行多次往返 通过一个网页实际发送

使用HTTP/2,服务器可以向index.html GET发送响应 push承诺告诉客户它也将发送 theme.css、jquery.js、logo.png等,就好像客户要求 他们。然后,客户端可以取消这些推送,或者只是等待推送 发送时不会引起多次往返的额外延迟

以下是关于jetty中HTTP2和SPDY的推送API的博客:

解决

我收到了以下来自支持部门的回复

iOS目前不支持此功能


更新

(@vin25评论)


ios10支持它。

您好,欢迎使用SO。你应该发布你的代码,并详细说明你遇到了什么样的接收问题!谢谢你提供的信息!你能告诉我你是否知道NSURLSession支持这个吗?是的……而且HTTP/2支持是iOS 9的一部分,因此在早期的OS版本上不可用。嗯……我可以看到只有iOS 9(或更高版本)支持HTTP/2。。。但是我不知道iOS9的cocoaapi是否有SURVER_PUSH…>的功能,有什么更新吗?iOS 10中是否添加了对此的支持?最近发现iOS 10确实支持它。请参阅关于NSURLSession-的WWDC 2016视频。我已经测试过了,它工作得很好!