{"id":209736,"date":"2014-01-21T09:14:03","date_gmt":"2014-01-21T05:14:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=209736"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=209736","title":{"rendered":"<span class=\"post_title\">\u041f\u043e\u0447\u0435\u043c\u0443 NSURLSession \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c NSURLConnection<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t<img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/776\/4e6\/a0f\/7764e6a0f91b056b2fa19c3b39714585.png\"\/><\/p>\n<p>  iOS 7 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0432\u044b\u0448\u043b\u0430 \u0432 \u0441\u0435\u043d\u0442\u044f\u0431\u0440\u0435, \u0442\u043e\u0433\u0434\u0430 Apple \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c \u043d\u043e\u0432\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0435\u0442\u044c\u044e \u2014 NSURLSession. \u042d\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0444\u0443\u043d\u0434\u0430\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0449\u044c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 iOS 6 \u0438 \u043d\u0438\u0436\u0435, \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u0435\u0440\u0441\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0431\u0443\u0434\u0435\u0442 \u043a\u0440\u0430\u0439\u043d\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0442\u0438\u0447\u043d\u043e. \u041d\u043e \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0432\u0440\u0435\u043c\u044f \u0438\u0434\u0435\u0442, \u0438 \u0443\u0436\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u043e\u0442 75 \u0434\u043e 85 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043f\u0435\u0440\u0435\u0448\u043b\u043e \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e iOS, \u043f\u043e\u0442\u043e\u043c\u0443 \u044f \u0431\u044b \u0441\u043e\u0432\u0435\u0442\u043e\u0432\u0430\u043b \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c NSURLSession \u0443\u0436\u0435 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435.<\/p>\n<p>  \u041f\u043e \u0437\u0430\u043c\u044b\u0441\u043b\u0443 Apple, NSURLSession \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u043c\u0435\u043d\u0438\u0442\u044c NSURLConnection, \u0438 \u0442\u0443\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441: \u00ab\u0430 \u0437\u0430\u0447\u0435\u043c \u0432\u0441\u0435 \u044d\u0442\u043e \u043d\u0430\u0434\u043e?\u00bb \u041f\u043e\u0442\u043e\u043c\u0443 \u0441\u0440\u0430\u0437\u0443 \u043f\u043b\u044e\u0441\u044b \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 NSURLConnection:  <\/p>\n<ol>\n<li>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0431\u044d\u043a\u0433\u0440\u0430\u0443\u043d\u0434\u0435<\/li>\n<li>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443<\/li>\n<li>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043b\u043e\u043a\u0438 \u0438 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u044b \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e, \u0442\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0431\u043b\u043e\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a, \u0430 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u2014 \u0434\u043b\u044f \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/li>\n<li>\u0423 \u0441\u0435\u0441\u0441\u0438\u0438 \u0435\u0441\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u0441\u0435 \u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0442\u0430\u0441\u043a\u043e\u0432(\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432) \u0432 \u0441\u0435\u0441\u0441\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0445\u044d\u0434\u0435\u0440\u044b \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0441\u0435\u0441\u0441\u0438\u0438<\/li>\n<li>\u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0434\u043b\u044f \u043a\u0443\u043a\u043e\u0432, \u043a\u044d\u0448\u0430 \u0438 \u043f\u0440\u043e\u0447\u0435\u0433\u043e<\/li>\n<li>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0440\u043e\u0433\u0438\u0439 \u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043d\u0430\u0431\u043e\u0440\u0430 \u0431\u0435\u0441\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u043d\u044b\u0445 NSURLConnection<\/li>\n<\/ol>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u041f\u043e\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u043d\u043e\u0432\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0441\u0442\u0440\u0430\u0448\u043d\u044b\u0439 \u0438 \u0447\u0442\u043e \u0435\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u0418\u0442\u0430\u043a \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c, \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f NSURLSession, \u043a\u0430\u043a \u044f\u0441\u043d\u043e \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u043e\u043d \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u0435\u043a\u0443\u044e \u0441\u0435\u0441\u0441\u0438\u044e, \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438\/\u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 HTTP. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0440\u0438 \u0442\u0438\u043f\u0430 \u0441\u0435\u0441\u0441\u0438\u0438: <b>default<\/b> \u2014 \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u0440\u0430\u043d\u044c\u0448\u0435 \u0434\u0435\u043b\u0430\u043b NSURLConnection, <b>ephemeral<\/b> \u2014 \u0432 \u043d\u0435\u0439 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043a\u044d\u0448\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u0432\u0441\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438(\u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0439 \u0440\u0435\u0436\u0438\u043c \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435), <b>download<\/b> \u2014 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u0444\u0430\u0439\u043b\u043e\u0432.<\/p>\n<h2>NSURLSessionConfiguration<\/h2>\n<p>  \u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 \u0441\u0435\u0441\u0441\u0438\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 NSURLSessionConfiguration, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0435\u0441\u0442\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043f\u043e\u043c\u0438\u043c\u043e \u0432\u044b\u0431\u043e\u0440\u0430 \u0442\u0438\u043f\u0430 \u0441\u0435\u0441\u0441\u0438\u0438: \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u0443\u044e \u0441\u0435\u0442\u044c, \u043a\u0443\u043a\u0438, \u043a\u044d\u0448, \u043f\u0440\u043e\u043a\u0441\u0438, \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c. \u0415\u0441\u0442\u044c \u043e\u0434\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e discretionary \u2014 \u043e\u043d\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0442\u0434\u0430\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043d\u0430 \u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b (\u043a\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 wi-fi \u0438 \u043c\u043d\u043e\u0433\u043e \u0437\u0430\u0440\u044f\u0434\u0430 \u0431\u0430\u0442\u0430\u0440\u0435\u0438).<\/p>\n<h2>NSURLSession<\/h2>\n<p>  \u0417\u0430\u0434\u0430\u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0441\u0435\u0441\u0441\u0438\u0438, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0430\u043c\u0443 \u0441\u0435\u0441\u0441\u0438\u044e, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435. \u0414\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u043c\u0438 \u0434\u0432\u0443\u043c\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438: \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 \u0438\u043b\u0438 \u043b\u043e\u0432\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 completion \u0431\u043b\u043e\u043a\u0435 (\u043e \u043d\u0438\u0445 \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435).<\/p>\n<h2>NSURLTask<\/h2>\n<p>  \u042f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439, \u0442\u043e \u0447\u0442\u043e \u0434\u043e \u044d\u0442\u043e \u0431\u044b\u043b\u043e NSURLConnection. \u0421\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u043a\u043b\u0430\u0441\u0441 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439, \u043d\u043e \u0443 \u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c 3 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u0430: NSURLSessionDataTask, NSURLSessionUploadTask (\u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441 \u043f\u0435\u0440\u0432\u043e\u0433\u043e) \u0438 NSURLSessionDownloadTask, \u0432\u043f\u0440\u043e\u0447\u0435\u043c, \u0438 \u0443 \u043d\u0438\u0445 \u043d\u0435\u0442 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430. \u0412\u0441\u0435 \u043e\u043d\u0438 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0441\u0430\u043c\u043e\u0439 \u0441\u0435\u0441\u0441\u0438\u0435\u0439 c completion \u0431\u043b\u043e\u043a\u043e\u043c \u0438\u043b\u0438 \u0431\u0435\u0437 (\u0432\u043f\u043e\u043b\u043d\u0435 \u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u0447\u0442\u043e \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u0435\u043b\u0435\u0433\u0430\u0442 \u0441\u0435\u0441\u0441\u0438\u0438 \u043d\u0435 \u043d\u0443\u0436\u0435\u043d). \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432\u0441\u0435 \u044d\u0442\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u043a\u0437\u043e\u0442\u0438\u0447\u043d\u043e:  <\/p>\n<pre><code class=\"objectivec\">NSURLSessionDownloadTask *downloadTask = [ourSession downloadTaskWithRequest:simpleNSURLRequest]; <\/code><\/pre>\n<h2>\u0411\u043b\u043e\u043a\u0438 \u0438 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u044b<\/h2>\n<p>  \u0412\u043e\u043e\u0431\u0449\u0435 \u0441\u0430\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0438\u043b\u044c\u043d\u043e \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 NSURLConnection, \u0431\u044b\u0441\u0442\u0440\u0435\u043d\u044c\u043a\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0432\u0430 \u043f\u0443\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0435\u0441\u0441\u0438\u044f\u043c\u0438.<\/p>\n<p>  <b>\u0427\u0435\u0440\u0435\u0437 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u044b:<\/b><br \/>   \u0421\u0435\u0441\u0441\u0438\u0438 \u0437\u0430\u0434\u0430\u0435\u043c \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f.  <\/p>\n<pre><code class=\"objectivec\">[NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil];<\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0432\u0441\u0435 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b (\u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u0442\u0430\u0441\u043a\u043e\u0432) \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0435.<\/p>\n<p>  <b>\u0427\u0435\u0440\u0435\u0437 \u0431\u043b\u043e\u043a\u0438:<\/b><br \/>   \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0438\u0448\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u0430\u0441\u043a\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e  <\/p>\n<pre><code class=\"objectivec\"> -(NSURLSessionDownloadTask *)downloadTaskWithRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURL *location, NSURLResponse *response, NSError *error))completionHandler<\/code><\/pre>\n<p>  \u041e\u043f\u044f\u0442\u044c \u0436\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e, \u0432\u0441\u0435 \u044d\u0442\u043e \u043d\u0430\u043c \u0437\u043d\u0430\u043a\u043e\u043c\u043e \u043f\u043e NSURLConnection -sendAsynchronousRequest:queue:completionHandler:<br \/>  \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440\u044b<\/h2>\n<p>  \u0420\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u0441 \u043e\u0431\u0449\u0435\u0439 \u0441\u0445\u0435\u043c\u043e\u0439, \u043e\u0442\u043b\u043e\u0436\u0438\u043c \u0442\u0435\u043e\u0440\u0438\u044e, \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u044b!<\/p>\n<h5>\u041e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430\/\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438.<\/h5>\n<p>  \u0412\u0441\u044f \u0441\u0445\u0435\u043c\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0447\u0435\u0440\u0435\u0437 NSURLConnection, \u043d\u043e, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043d\u0435\u0433\u043e, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0439 download \u0442\u0430\u0441\u043a. \u0422\u0430\u043a\u0436\u0435 \u043f\u0440\u0438 \u043e\u0442\u043c\u0435\u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 URLSession:task:didCompleteWithError:, \u0442\u0430\u043a \u0447\u0442\u043e \u0442\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 \u0441 UI. \u041f\u0440\u0438\u0447\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c, \u043d\u043e \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c.  <\/p>\n<pre><code class=\"objectivec\">  [self.resumableTask cancelByProducingResumeData:^(NSData *resumeData) {         partialDownload = resumeData;         self.resumableTask = nil;     }];      \/\/\u043e\u0442\u0434\u0430\u0435\u043c \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u043e\u0432\u043e\u043c\u0443 \u0442\u0430\u0441\u043a\u0443 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435     if(partialDownload) {         self.resumableTask = [inProcessSession downloadTaskWithResumeData:partialDownload];     } else {         ...     }     [self.resumableTask resume]; <\/code><\/pre>\n<p>  \u041e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044f \u0442\u0430\u0441\u043a \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0430 \u0443\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u043e\u0442\u0434\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u043e\u0432\u043e\u043c\u0443 download \u0442\u0430\u0441\u043a\u0443.<\/p>\n<h5>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0432 \u0444\u0430\u0439\u043b<\/h5>\n<p>  \u0415\u0449\u0435 \u043e\u0434\u043d\u0430 \u0432\u0435\u0449\u044c, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c, \u044d\u0442\u043e download \u0442\u0430\u0441\u043a\u0438. \u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u043e\u043d\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0435 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u0443\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0432 \u0444\u0430\u0439\u043b. <\/p>\n<p>  \u0447\u0435\u0440\u0435\u0437 \u0431\u043b\u043e\u043a:  <\/p>\n<pre><code class=\"objectivec\">NSURLSessionConfiguration* sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig]; NSURL* downloadTaskURL = [NSURL URLWithString:@&quot;http:\/\/upload.wikimedia.org\/wikipedia\/commons\/1\/14\/Proton_Zvezda_crop.jpg&quot;]; [[session downloadTaskWithURL: downloadTaskURL          completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {            NSFileManager *fileManager = [NSFileManager defaultManager];                        NSArray *urls = [fileManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];            NSURL *documentsDirectory = [urls objectAtIndex:0];                        NSURL *originalUrl = [NSURL URLWithString:[downloadTaskURL lastPathComponent]];            NSURL *destinationUrl = [documentsDirectory URLByAppendingPathComponent:[originalUrl lastPathComponent]];            NSError *fileManagerError;                        [fileManager removeItemAtURL:destinationUrl error:NULL];            \/\/\u043a\u043b\u044e\u0447\u0435\u0432\u0430\u044f  \u0441\u0442\u0440\u043e\u0447\u043a\u0430!            [fileManager copyItemAtURL:location toURL:destinationUrl error:&fileManagerError];                      }] resume]; <\/code><\/pre>\n<p>  \u0447\u0435\u0440\u0435\u0437 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434:  <\/p>\n<pre><code class=\"objectivec\">NSURLSessionConfiguration* sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig delegate:self delegateQueue:nil]; NSURL* downloadTaskURL = [NSURL URLWithString:@&quot;http:\/\/upload.wikimedia.org\/wikipedia\/commons\/1\/14\/Proton_Zvezda_crop.jpg&quot;]; [[session downloadTaskWithURL:downloadTaskURL] resume];  \/\/\u0442\u0435\u043f\u0435\u0440\u044c \u043b\u043e\u0432\u0438\u043c \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location {   \/\/\u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c } <\/code><\/pre>\n<p>  \u041d\u0430\u0434\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e location \u0430\u0434\u0440\u0435\u0441 \u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435:<br \/>  file:\/\/\/private\/var\/mobile\/Applications\/{appUUID}\/tmp\/CFNetworkDownload_fileID.tmp, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0444\u0430\u0439\u043b \u0432 \u0431\u043e\u043b\u0435\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e, \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 file:\/\/\/var\/mobile\/Applications\/{appUUID}\/Documents\/Proton_Zvezda_crop.jpg<\/p>\n<h5>\u041f\u043e\u0441\u044b\u043b\u0430\u0435\u043c \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0437\u0430 \u0440\u0430\u0437<\/h5>\n<p>  \u0418\u043d\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u2014 5. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439: <\/p>\n<pre><code class=\"objectivec\">sessionConfig.HTTPMaximumConnectionsPerHost = 5; <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c, \u043b\u0443\u0447\u0448\u0435 \u0437\u0430\u0431\u0438\u0440\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u043f\u043e\u0431\u043e\u043b\u044c\u0448\u0435, \u0441\u043e\u0432\u0435\u0442\u0443\u044e \u0442\u0430\u043a\u0436\u0435 \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0447\u0435\u0440\u0435\u0437 3g (Settings -&gt; Developer -&gt; Network link conditioner -&gt; Choose a profile -&gt; 3g -&gt; Enable)<\/p>\n<pre><code class=\"objectivec\">- (void) methodForNSURLSession{   NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];   _tasksArray = [[NSMutableArray alloc] init];   sessionConfig.HTTPMaximumConnectionsPerHost = 5;   sessionConfig.timeoutIntervalForResource = 0;   sessionConfig.timeoutIntervalForRequest = 0;   NSURLSession* session = [NSURLSession sessionWithConfiguration:sessionConfig delegate:self delegateQueue:nil];    \/\/ download tasks   \/\/  [self createDataTasksWithSession:session];    \/\/ data tasks   [self createDownloadTasksWithSession:session]; }  - (void) createDownloadTasksWithSession:(NSURLSession *)session{   for (int i = 0; i &lt; 10; i++) {     NSURLSessionDownloadTask *sessionDownloadTask = [session downloadTaskWithURL: [NSURL URLWithString:@&quot;https:\/\/discussions.apple.com\/servlet\/JiveServlet\/showImage\/2-20930244-204399\/iPhone%2B5%2BProblem2.jpg&quot;]];     [_tasksArray addObject:sessionDownloadTask];     [sessionDownloadTask addObserver:self forKeyPath:@&quot;countOfBytesReceived&quot; options:NSKeyValueObservingOptionOld context:nil];     [sessionDownloadTask resume];   } }  - (void) createDataTasksWithSession:(NSURLSession *)session{   for (int i = 0; i &lt; 10; i++) {     NSURLSessionDataTask *sessionDataTask = [session dataTaskWithURL: [NSURL URLWithString:@&quot;https:\/\/discussions.apple.com\/servlet\/JiveServlet\/showImage\/2-20930244-204399\/iPhone%2B5%2BProblem2.jpg&quot;]];     [_tasksArray addObject:sessionDataTask];     [sessionDataTask addObserver:self forKeyPath:@&quot;countOfBytesReceived&quot; options:NSKeyValueObservingOptionOld context:nil];     [sessionDataTask resume];   } }  - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{   if([[change objectForKey:@&quot;old&quot;] integerValue] == 0){     NSLog(@&quot;task %d: started&quot;, [_tasksArray indexOfObject: object]);   } }  - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error{   NSLog(@&quot;task %d: finished!&quot;, [_tasksArray indexOfObject:task]); } <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u0439, \u043d\u043e \u0437\u0430\u043e\u0441\u0442\u0440\u044e \u0432\u0430\u0448\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u043c\u043e\u043c\u0435\u043d\u0442\u0435:  <\/p>\n<pre><code class=\"objectivec\">sessionConfig.timeoutIntervalForResource = 0; sessionConfig.timeoutIntervalForRequest = 0; <\/code><\/pre>\n<p>  \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438:<br \/>  timeoutIntervalForRequest \u2014 \u0432\u0440\u0435\u043c\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0442\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0430\u0441\u043a\u0430<br \/>  timeoutIntervalForResource \u2014 \u0432\u0440\u0435\u043c\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0442\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<br \/>  \u0438 \u0442\u0443\u0442 \u0443 \u043d\u0430\u0441 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u0434\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0442\u0430\u0441\u043a ([task resume]) \u0441\u0447\u0435\u0442\u0447\u0438\u043a timeoutIntervalForRequest \u043d\u0430\u0447\u0430\u043b \u0442\u0438\u043a\u0430\u0442\u044c, \u0438 \u043d\u0438\u043a\u043e\u0433\u043e \u043d\u0435 \u0432\u043e\u043b\u043d\u0443\u0435\u0442, \u0447\u0442\u043e \u0442\u0430\u0441\u043a\u043e\u0432 \u0443 \u043d\u0430\u0441 100, \u0430 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043c\u043e\u0436\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e 5. \u041f\u043e \u044d\u0442\u043e\u0439 \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c, \u0432\u0435\u0434\u044c \u0442\u0430\u0441\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u044b \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c\u0438, \u043c\u043e\u0433\u0443\u0442 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u044c\u0441\u044f \u0442\u0430\u043a \u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0432 \u043d\u0435 \u0431\u0438\u0442\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. <\/p>\n<p>  \u041f\u043e\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043a\u0440\u043e\u043c\u0435 \u043a\u0430\u043a \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043e\u0431\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 0, \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0431\u0443\u0434\u0435\u0442 \u0438\u0434\u0442\u0438 \u0434\u043e \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0441\u0442\u0438. <\/p>\n<p>  \u0414\u0430, \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u043e\u0431\u0440\u0435\u0441\u0442\u0438 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434 \u0438 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0442\u0430\u0441\u043a\u043e\u0432, \u043d\u043e \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0432\u0435\u0434\u044c \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u00ab\u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438\u00bb. \u0422\u0443\u0442, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0438\u043d\u0436\u0435\u043d\u0435\u0440\u044b Apple \u043d\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0434\u043e\u0434\u0443\u043c\u0430\u043b\u0438.<\/p>\n<h5>\u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438<\/h5>\n<p>  \u0423 download \u0442\u0430\u0441\u043a\u043e\u0432 \u0435\u0441\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434:  <\/p>\n<pre><code class=\"objectivec\">- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite {   double progress = (double)totalBytesWritten \/ (double)totalBytesExpectedToWrite;   NSLog(@&quot;download: %@ progress: %f&quot;, downloadTask, progress);   dispatch_async(dispatch_get_main_queue(), ^{     self.progressView.progress = progress;   }); } <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0436\u0435 \u0442\u0430\u0441\u043a\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f KVO \u043a\u0430\u043a \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435.<\/p>\n<h5>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0432 \u0431\u044d\u043a\u0433\u0440\u0430\u0443\u043d\u0434\u0435<\/h5>\n<p>  \u041d\u0443 \u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0432 \u0431\u044d\u043a\u0433\u0440\u0430\u0443\u043d\u0434\u0435, \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442 \u0434\u0435\u043c\u043e \u0438\u0437 wwdc&#8217;13 705. \u041b\u0438\u0447\u043d\u043e \u043c\u0435\u043d\u044f \u0434\u0435\u043c\u043a\u0430 \u043f\u043e\u0442\u0440\u044f\u0441\u043b\u0430. \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438, \u0432\u044b\u0445\u043e\u0434\u0438\u043c \u0438\u0437 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u2014 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u0430 \u0438 \u0443\u0436\u0435 \u0443\u043b\u043e\u0436\u0435\u043d\u0430, \u043f\u0440\u0438\u0447\u0435\u043c \u044d\u0442\u043e \u0432\u0438\u0434\u043d\u043e \u0434\u0430\u0436\u0435 \u0432 \u043c\u0443\u043b\u044c\u0442\u0438\u0442\u0430\u0441\u043a \u043c\u0435\u043d\u044e\u0448\u043a\u0435 (\u0442\u0430, \u0447\u0442\u043e \u043f\u043e \u0434\u0432\u043e\u0439\u043d\u043e\u043c\u0443 \u043d\u0430\u0436\u0430\u0442\u0438\u044e \u043d\u0430 \u0434\u043e\u043c\u0430\u0448\u043d\u044e\u044e \u043a\u043d\u043e\u043f\u043a\u0443). \u041d\u043e \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0443\u0440\u043e\u043d\u0438\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u2014 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u0441\u044f \u0438 \u0432\u0441\u0435 \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u0431\u0443\u0434\u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e! \u0414\u0430 \u0435\u0449\u0435 \u0438 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0448 UI \u043f\u0440\u044f\u043c \u0432 \u0431\u044d\u043a\u0433\u0440\u0430\u0443\u043d\u0434\u0435, \u0438 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u043d\u0430\u043f\u0448\u043e\u0442 \u0432 \u043c\u043d\u043e\u0433\u043e\u0437\u0430\u0434\u0430\u0447\u043d\u043e\u043c \u043c\u0435\u043d\u044e. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043d\u0435 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u2014 \u044d\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u0430\u043c \u0443\u0431\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043d\u043e \u0442\u0443\u0442 \u0443\u0436 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u0434\u0435\u043b\u0430\u0435\u0448\u044c, \u0445\u043e\u0437\u044f\u0438\u043d \u2014 \u0431\u0430\u0440\u0438\u043d.<\/p>\n<p>  \u041f\u043e\u0447\u0435\u043c\u0443 \u0436\u0435 \u0442\u0430\u043a\u0430\u044f \u00ab\u043c\u0430\u0433\u0438\u044f\u00bb \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442? \u0412\u0441\u0435 \u0434\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0431\u044d\u043a\u0433\u0440\u0430\u0443\u043d\u0434 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u2014 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0434\u0435\u043c\u043e\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u041e\u043d\u043e \u0438 \u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e-\u0442\u043e, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0436\u0438\u0442\u044c \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041f\u043e \u044d\u0442\u043e\u0439 \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043d\u0430\u043c \u043d\u0435 \u0441\u0442\u0440\u0430\u0448\u043d\u044b \u043d\u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430, \u043d\u0438 \u043a\u0440\u044d\u0448 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041f\u043e\u0441\u043b\u0435 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u0434\u0435\u043c\u043e\u043d \u00ab\u0431\u0443\u0434\u0438\u0442\u00bb \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0435\u0441\u0441\u0438\u044e \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0439 \u0441\u0435\u0441\u0441\u0438\u0438 \u0441\u043e \u0441\u0442\u0430\u0440\u044b\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c \u00ab\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u00bb \u043d\u0430\u0441 \u043a \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0431\u044d\u043a\u0433\u0440\u0430\u0443\u043d\u0434 \u0441\u0435\u0441\u0441\u0438\u0438.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b, \u0441\u0430\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/github.com\/AlloyDev\/ADBackgroundDownloadExample\">\u0437\u0430\u0431\u0440\u0430\u0442\u044c \u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0432 \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u043e\u0432\u043e\u043c \u0441\u0442\u0438\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0435\u0441\u0441\u0438\u044e:  <\/p>\n<pre><code class=\"objectivec\">- (NSURLSession *)backgroundSession{   static NSURLSession *session = nil;   static dispatch_once_t onceToken;   dispatch_once(&onceToken, ^{     \/\/ \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0431\u044d\u043a\u0433\u0440\u0430\u0443\u043d\u0434 \u0441\u0435\u0441\u0441\u0438\u0438 \u043d\u0430\u0434\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u044e\u0447, \u043a \u0441\u0447\u0430\u0441\u0442\u044c\u044e \u043d\u0435 \u0434\u043b\u044f \u0442\u0430\u0441\u043a\u0430     NSURLSessionConfiguration *config = [NSURLSessionConfiguration backgroundSessionConfiguration:@&quot;com.dev.BackgroundDownloadTest.BackgroundSession&quot;];     [config setAllowsCellularAccess:YES];     session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil];   });   return session; } <\/code><\/pre>\n<p>  \u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 (\u0442\u0443\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0442\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e):   <\/p>\n<pre><code class=\"objectivec\"> self.downloadTask = [[self backgroundSession] downloadTaskWithURL:[NSURL URLWithString:@&quot;https:\/\/discussions.apple.com\/servlet\/JiveServlet\/showImage\/2-20930244-204399\/iPhone%2B5%2BProblem2.jpg&quot;]];   [self.downloadTask resume]; <\/code><\/pre>\n<p>  \u0412 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u0434\u043b\u044f \u0431\u044d\u043a\u0433\u0440\u0430\u0443\u043d\u0434 \u0442\u0430\u0441\u043a\u043e\u0432 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0438 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0435\u0435:  <\/p>\n<pre><code class=\"objectivec\">- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location {   \/\/ save image   \/\/ \u0431\u044b\u043b\u043e \u0432\u044b\u0448\u0435   \/\/...   \/\/ set image   if (success) {     dispatch_async(dispatch_get_main_queue(), ^{       self.imageView.image = [UIImage imageWithContentsOfFile:[destinationPath path]];       [self.progressView setHidden:YES];     });   } } <\/code><\/pre>\n<p>  \u0412 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u0434\u043b\u044f \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0443\u0436\u0435 \u0432\u0441\u0435\u0445 \u0442\u0430\u0441\u043a\u043e\u0432 \u043e\u0442\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u044d\u0442\u043e\u0442 \u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434\u044b)  <\/p>\n<pre><code class=\"objectivec\">- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {   if (error) {     NSLog(@&quot;error: %@ - %@&quot;, task, error);   } else {     NSLog(@&quot;success: %@&quot;, task);   }   self.downloadTask = nil;    \/\/\u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u0432\u0441\u0435 \u0442\u0430\u0441\u043a\u0438 \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d\u044b   [self callCompletionHandlerIfFinished]; } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u043c\u0441\u044f \u0432 AppDelegate.m<br \/>  \u041d\u0430\u043c \u043d\u0430\u0434\u043e \u043b\u043e\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d\u0430:  <\/p>\n<pre><code class=\"objectivec\">- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)())completionHandler {   \/\/\u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u043c \u0432\u0438\u0434\u0435\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d\u0430   UILocalNotification* locNot = [[UILocalNotification alloc] init];   locNot.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];   locNot.alertBody = [NSString stringWithFormat:@&quot;still alive!&quot;];   locNot.timeZone = [NSTimeZone defaultTimeZone];   [[UIApplication sharedApplication] scheduleLocalNotification:locNot];      \/\/\u0441\u0440\u0435\u0434\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0438\u0441\u0438\u0442 \u0437\u0430\u0433\u0430\u0434\u043e\u0447\u043d\u044b\u0439 \u0445\u0435\u043d\u0434\u043b\u0435\u0440 - \u0435\u0433\u043e \u043d\u0430\u0434\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u043e\u0431\u0449\u0438\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043e \u0442\u043e\u043c,   \/\/\u0447\u0442\u043e \u043c\u044b \u043e\u0431\u043d\u043e\u0432\u0438\u043b\u0438 UI \u0438 \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0441\u043d\u0430\u043f\u0448\u043e\u0442 \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u043e\u0437\u0430\u0434\u0430\u0447\u043d\u043e\u0433\u043e \u043c\u0435\u043d\u044e.   \/\/\u041f\u043e\u0442\u043e\u043c\u0443 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0435\u0433\u043e \u0434\u043e \u043b\u0443\u0447\u0448\u0438\u0445 \u0432\u0440\u0435\u043c\u0435\u043d   self.backgroundSessionCompletionHandler = completionHandler; } <\/code><\/pre>\n<p>  \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440.<br \/>  \u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0441\u0435\u0441\u0441\u0438\u044e, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e:  <\/p>\n<pre><code class=\"objectivec\">- (void)viewDidLoad {   [super viewDidLoad];   [self backgroundSession]; } <\/code><\/pre>\n<p>  \u041c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u043d\u0446\u0435:  <\/p>\n<pre><code class=\"objectivec\">- (void)callCompletionHandlerIfFinished {   NSLog(@&quot;call completion handler&quot;);   [[self backgroundSession] getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {     NSUInteger count = [dataTasks count] + [uploadTasks count] + [downloadTasks count];     if (count == 0) {     \/\/ \u0432\u0441\u0435 \u0442\u0430\u0441\u043a\u0438 \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d\u044b     \/\/ \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u043f\u0440\u0438\u043f\u0440\u044f\u0442\u0430\u043d\u043d\u044b\u0439 \u0445\u044d\u043d\u0434\u043b\u0435\u0440     \/\/ \u0438 \u043e\u0442\u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043e\u0431 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 UI       NSLog(@&quot;all tasks ended&quot;);       AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];       if (appDelegate.backgroundSessionCompletionHandler == nil) return;       void (^comletionHandler)() = appDelegate.backgroundSessionCompletionHandler;       appDelegate.backgroundSessionCompletionHandler = nil;       comletionHandler();     }   }]; } <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044e, \u0447\u0442\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u044d\u0442\u043e\u0442 \u0445\u044d\u043d\u0434\u043b\u0435\u0440, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0432 \u043b\u043e\u0433 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435:  <\/p>\n<pre><code class=\"objectivec\">Warning: Application delegate received call to - application:handleEventsForBackgroundURLSession:completionHandler: but the completion handler was never called. <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435, \u0435\u0441\u043b\u0438 \u043c\u044b \u043e\u0442\u043a\u0440\u043e\u0435\u043c \u043c\u043d\u043e\u0433\u043e\u0437\u0430\u0434\u0430\u0447\u043d\u043e\u0435 \u043c\u0435\u043d\u044e, \u043c\u044b \u043d\u0435 \u0443\u0432\u0438\u0434\u0438\u043c \u043d\u0430\u0448\u0435\u0433\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u044d\u0442\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u0430 \u0438\u0437 \u0441\u0442\u043e\u0440\u043e\u043d \u043c\u043d\u043e\u0433\u043e\u0437\u0430\u0434\u0430\u0447\u043d\u043e\u0433\u043e \u00abUI\u00bb, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 Apple.<\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0435, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0434\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u0434\u0432\u0438\u0433\u043d\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c NSURLSession \u0432 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445! \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/209736\/\"> http:\/\/habrahabr.ru\/post\/209736\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t<img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/776\/4e6\/a0f\/7764e6a0f91b056b2fa19c3b39714585.png\"\/><\/p>\n<p>  iOS 7 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0432\u044b\u0448\u043b\u0430 \u0432 \u0441\u0435\u043d\u0442\u044f\u0431\u0440\u0435, \u0442\u043e\u0433\u0434\u0430 Apple \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c \u043d\u043e\u0432\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0435\u0442\u044c\u044e \u2014 NSURLSession. \u042d\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0444\u0443\u043d\u0434\u0430\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0449\u044c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 iOS 6 \u0438 \u043d\u0438\u0436\u0435, \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u0435\u0440\u0441\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0431\u0443\u0434\u0435\u0442 \u043a\u0440\u0430\u0439\u043d\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0442\u0438\u0447\u043d\u043e. \u041d\u043e \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0432\u0440\u0435\u043c\u044f \u0438\u0434\u0435\u0442, \u0438 \u0443\u0436\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u043e\u0442 75 \u0434\u043e 85 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043f\u0435\u0440\u0435\u0448\u043b\u043e \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e iOS, \u043f\u043e\u0442\u043e\u043c\u0443 \u044f \u0431\u044b \u0441\u043e\u0432\u0435\u0442\u043e\u0432\u0430\u043b \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c NSURLSession \u0443\u0436\u0435 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435.<\/p>\n<p>  \u041f\u043e \u0437\u0430\u043c\u044b\u0441\u043b\u0443 Apple, NSURLSession \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u043c\u0435\u043d\u0438\u0442\u044c NSURLConnection, \u0438 \u0442\u0443\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441: \u00ab\u0430 \u0437\u0430\u0447\u0435\u043c \u0432\u0441\u0435 \u044d\u0442\u043e \u043d\u0430\u0434\u043e?\u00bb \u041f\u043e\u0442\u043e\u043c\u0443 \u0441\u0440\u0430\u0437\u0443 \u043f\u043b\u044e\u0441\u044b \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 NSURLConnection:  <\/p>\n<ol>\n<li>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0431\u044d\u043a\u0433\u0440\u0430\u0443\u043d\u0434\u0435<\/li>\n<li>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443<\/li>\n<li>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043b\u043e\u043a\u0438 \u0438 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u044b \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e, \u0442\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0431\u043b\u043e\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a, \u0430 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u2014 \u0434\u043b\u044f \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/li>\n<li>\u0423 \u0441\u0435\u0441\u0441\u0438\u0438 \u0435\u0441\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u0441\u0435 \u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0442\u0430\u0441\u043a\u043e\u0432(\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432) \u0432 \u0441\u0435\u0441\u0441\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0445\u044d\u0434\u0435\u0440\u044b \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0441\u0435\u0441\u0441\u0438\u0438<\/li>\n<li>\u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0434\u043b\u044f \u043a\u0443\u043a\u043e\u0432, \u043a\u044d\u0448\u0430 \u0438 \u043f\u0440\u043e\u0447\u0435\u0433\u043e<\/li>\n<li>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0440\u043e\u0433\u0438\u0439 \u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043d\u0430\u0431\u043e\u0440\u0430 \u0431\u0435\u0441\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u043d\u044b\u0445 NSURLConnection<\/li>\n<\/ol>\n<p>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-209736","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/209736","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=209736"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/209736\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=209736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=209736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=209736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}