小编Dar*_*koB的帖子

NSURLConnection在iOS 4.3中完美运行,但在iOS 5/iOS 6中运行不佳

我在NSURLConnection有一些非常奇怪的问题,所以我希望你能帮助我.

我想要做的是使用NSURLConnection从给定的URL下载一些数据.

我创建了自己的帮助程序类,它接收数据路径,下载它,并在下载完成时通过委托通知调用者.

这款产品在iOS 4.3上完美搭配.但是,在iOS 5或iOS6上进行测试时,connection:(NSURLConnection *)connection didReceiveData:(NSData *)data永远不会调用该方法,也无法获得所需的结果.

类.h文件包含:

#import <Foundation/Foundation.h>

@protocol NIAsyncDownloaderDelegate
@required
- (void) asyncDownloaderDataDownloadComplete:(NSData *)data withError:(bool) error;
@end

@interface NIAsyncImageDownloader : NSObject <NSURLConnectionDataDelegate>
{
    NSURLConnection *theConnection;
    NSMutableData* myData;

    NSURL *downloadURL;

    id delegate;
}

-(id) initWithDataDownloadString:(NSString *) stringAddress;

@property (nonatomic, retain) id delegate;

@end
Run Code Online (Sandbox Code Playgroud)

并且.m文件如下所示:

#import "NIAsyncDownloader.h"

@implementation NIAsyncImageDownloader

@synthesize delegate;

-(id) initWithDataDownloadString:(NSString *)stringAddress
{
    if (self = [super init])
    {
        [self loadDataFromURL:[NSURL URLWithString:stringAddress]];
    }
    return self;
}

- (void)loadDataFromURL:(NSURL*)url
{
    NSLog(@"Called: %@", NSStringFromSelector(_cmd));
    downloadURL …
Run Code Online (Sandbox Code Playgroud)

objective-c nsurlconnection ios

5
推荐指数
1
解决办法
314
查看次数

标签 统计

ios ×1

nsurlconnection ×1

objective-c ×1