我有一個應用程序需要下載聲音文件才能正常工作。當我開始使用NsurlConnection下載時,我的應用程序會掛起
我正在使用NSURLConnection
異步下載我的文件,它的大小超過20Mb。 爲了跟蹤下載的百分比,我放置了一個progressBarView
,並且我使用Apple建議的代理方法NSUrlConnection
。
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];
}
和So ...
當我開始下載,界面掛起不時和progressView
掛起也是如此。
一個值得注意的事情,也許是另一個問題: 我禁用了用戶界面,所以用戶必須等到下載完成,當然,我給他一個消息告訴他。 Apple會否拒絕我的應用程序?我非常擔心的是
感謝您閱讀我的問題:)默認的NSURLConnectionDelegate
附加活動的指標在動畫啓動和停止時animationg完成下載 –