UI中的网络请求

NSURLConnectionDataDelegate

{

totleLength;

* filedata;

isDownload;

reciveTotle;

* filePath;

* _connection;

}

@end


ViewController


- () viewDidLoad {

viewDidLoad

//做任何额外的设置加载视图后,通常从笔尖。

NSUserDefaultsNSUserDefaults

=[[userDefaults:]];

=[[userDefaults:]];

(>) {

进步=/;

. .=进步;

. .=[ :,progress * ];

}

}

- ()btnClick:( *)sender {

isDownload

;

}

@"http://free2.macx.cn:8182/game/BombSquadX401.dmg"

NSMutableURLRequestNSMutableURLRequest

(> ) {

*value=https://www.yisu.com/zixun/[ :,()];

[request :value :];

}

connectionWithRequestdelegate

isDownload

NSStringabsoluteString

*strName=[str ];

NSHomeDirectorystringByAppendingFormat

defaultManagerfileExistsAtPath

defaultManagercreateFileAtPathcontentsattributes

}


}

- ()pauseAction:( *)sender {

_connection

_connection

appendFileData

NSUserDefaultsNSUserDefaults

[userDefaults : :];

[userDefaults : :];

[userDefaults ];

isDownload

}

#pragma mark-NSURLConnectionDataDelegate

- ()connection:( *)connection didReceiveResponse:( *)response{

=[[ ]];

NSDictionaryallHeaderFields

*number=[dic :];

=[number ];

}

- ()connection:( *)connection didReceiveData:( *)data{

[ :data];

+=data.;

progressViewreciveTotletotleLength

progressLabelprogressView

(.>=*){

appendFileData

。=,

}

}


- () appendFileData:数据(*)

{

(数据。==){

,

}

fileHandleForWritingAtPath

[文件];

[文件句柄:数据];

[文件];

}

- () connectionDidFinishLoading:(*)连接{

(。<*){

appendFileData

[:];

writeToFileatomically

}

progressLabel isDownload

}



UI中的网络请求