我有一个应用程序需要下载声音文件才能正常工作。
我正在使用NSURLConnection
异步下载超过 20Mb 的文件。我放置了一个progressBarView
以跟踪下载百分比,并且我正在使用NSUrlConnection
Apple 建议的委托方法。
NSURLRequest *theRequest=[NSURLRequest requestWithURL:soundFileURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
// create the connection with the request
// and start loading the data
NSURLConnection *theConnection;
theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
//[theConnection cancel];
//[theConnection start];
if (theConnection) {
// Create the NSMutableData that will hold
// the received data
// receivedData is declared as a method instance elsewhere
receivedData=[[NSMutableData data] retain];
} else {
// inform the user that the download could not be made
}
和委托方法
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[receivedData appendData:data];
}
所以 ...
当我开始下载时,界面不时progressView
挂起,也挂起。
一件值得注意的事情,也许还有另一个问题:我禁用了用户界面,所以用户必须等到下载完成,当然,我给他一条消息告诉他。苹果会因此拒绝我的应用程序吗?我非常担心
感谢您阅读我的问题:)