MonoTouch: How to download pdf incrementally as indicated in the Apple slides “Building Newsstand Apps”, Session 504?

自作多情 提交于 2020-02-04 07:20:13

问题


This is a followup to : MonoTouch: How to save a huge PDF downloaded from an URL incrementally?

I'm trying to follow the guidelines indicated by the Apple slides of the Newsstand presentation ("Building Newsstand Apps", Session 504):

http://adcdownload.apple.com//wwdc_2011/adc_on_itunes__wwdc11_sessions__pdf/504_building_newsstand_apps.pdf

Apple recommends the use of the NSURLConnection Delegate and NKAssetDownload for downloading and resuming the newsstand content, but I don't understand what C# code in MonoTouch is equivalent to the one in Obj-C showed in the slides.

The problem is how to download a huge PDF file from an URL in my MonoTouch iPhone/iPad newsstand app, a PDF that is often too big to fit in memory.

To execute the download incrementally as indicated in the slides, instead of appending all the downloaded data in NSData and at the very end of the download and store it to a file when I got all data, I need to execute the download asynchronously in a separate thread and append to a file each received chunk and free my memory.

At the same time I need to be certain that if the connection is dropped or the app crashes the download would resume automatically from the last chunk without corrupting the file.

What is the better way to handle this in MonoTouch, without risking to see my App rejected by Apple?

Thanks in advance!


回答1:


A sample showing how you setup the NSUrlConnectionDelegate can be found here:

https://github.com/xamarin/monotouch-samples/blob/master/HttpClient/Cocoa.cs

That code shows how to create an NSUrlRequest, and how to pass an NSUrlConnectionDelegate (it is the "this" parameter in line 32).

The sample overrides a handful of methods from NSUrlConnectionDelegate, you would likely override more, based on what you want to support.



来源:https://stackoverflow.com/questions/8688197/monotouch-how-to-download-pdf-incrementally-as-indicated-in-the-apple-slides-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!