小编Soh*_*ail的帖子

ConnectionWithRequest 在 iOS 9.0 中已弃用

我想从主机下载一些项目,但现在收到警告: 'connectionWithRequest:delegate:'is deprecated in iOS9.0 - Use NSURLSession'

我到处搜索,但不幸的是我找不到任何解决方案。

你能帮助我吗?

我的代码如下所示:

- (void)downloadItems
{
    // Download the json file
    NSURL *jsonFileUrl = [NSURL URLWithString:@"http://myhost.com/test.php"];

    // Create the request
    NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:jsonFileUrl];

    // Create the NSURLConnection
    [NSURLConnection connectionWithRequest:urlRequest delegate:self];
}

#pragma mark NSURLConnectionDataProtocol Methods

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    // Initialize the data object
    _downloadedData = [[NSMutableData alloc] init];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    // Append the newly downloaded data
    [_downloadedData appendData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection …
Run Code Online (Sandbox Code Playgroud)

json objective-c ios nsurlsession ios9

4
推荐指数
1
解决办法
7283
查看次数

标签 统计

ios ×1

ios9 ×1

json ×1

nsurlsession ×1

objective-c ×1