5

I am currently creating an iOS Newsstand app. I have issues added and working the way I want. However, when I try to go and download their remote file, it doesn't seem to be working. None of the delegate methods are getting called and no file is being written.

This is what I have for certain:

  • A UITableViewController that is a NSURLConnectionDownloadDelegate.
  • UIBackgroundModes (in the info.plist file) has 'newsstand-content' added
  • #import is in the header of my UITableViewController
  • NSURLConnectionDownloadDelegate's methods are implemented

The Following code happens when the user agrees to download the issue (Note: Issue is not nil):

  // Download the Issue!
    NSLog(@"Starting Download of issue %@",issue.name);

    // Generate the url of the issue         
    NSURL * downloadURL = [dataManager pdfURLForIssue:issue];

    // Create the request
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:downloadURL
                                                           cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
                                                       timeoutInterval:30.0];

    // Create the NKAssetDownload object
    NKAssetDownload *assetDownload = [issue addAssetWithRequest:request];

    // Set user info so I know which issue's UIProgressView to update 
    [assetDownload setUserInfo:[NSDictionary dictionaryWithObjectsAndKeys:issue.name,@"Name",
                                nil]];

    // start download
    [assetDownload downloadWithDelegate:self];

I have no idea what is going on. From all I have read, I seem to have implemented everything properly; however, nothing is happening. I set breakpoints, NSLogs and such; but nothing. I even let it run for a while then checked the director the [issue contentURL] said the file would be moved too (in my connectionDidFinishDownloading:destinationURL: method).

Can anybody help? Or maybe some ideas for me? I have been stuck for days. If you need to see more code, just let me know. Thank you!

Johnny
  • 3,047
  • 1
  • 22
  • 18
  • Are you calling this method from a background thread or a global GCD queue? – Jason Coco Jan 10 '12 at 05:20
  • Not that I am aware. I first display a UIAlertView and if the "Download" button is tapped then the above code is being called. More specifically, it is being executed in the "alertView:clickedButtonAtIndex:" method. – Johnny Jan 10 '12 at 07:24
  • That wouldn't be defaulting to the background would it? – Johnny Jan 11 '12 at 04:02
  • Yeah, that callback should come on the main queue. – Jason Coco Jan 11 '12 at 04:15
  • Hm, well do you have any suggestions on how I could figure this out? It is hard because I have been doing everything the documentation says to do but still nothing. Is there a setting I have forgotten to set? Also, thank you very much for your time. I am grateful. – Johnny Jan 11 '12 at 05:01
  • Sorry, I haven't really used the newsstand kit yet. Could it possibly be a provisioning issue? Try checking the device console through Xcode organizer and see if any other processes are logging issues when your code makes these calls. These are just guesses tho. Hopefully somebody with some xp comes along. – Jason Coco Jan 11 '12 at 05:11
  • Will do and thank you for the advice. I appreciate it a lot. – Johnny Jan 11 '12 at 07:32

2 Answers2

3

I finally solved it. I started a completely new project and did all the download testing on that one. Turns out (I could be wrong but it is what I have found) that even though a normal NSURLConnection or download request works in the iPhone/iPad Simulator it seems that NKAssetDownload will not work unless it is running on an actual device.

To summarize, I wasn't doing anything wrong code-wise; however, I needed to run the application on an actual device for the NKAssetDownload objects would start downloading. Granted, it could have just been my experience but it has solved my problem.

I hope this helps others who are running into similar issues.

Johnny
  • 3,047
  • 1
  • 22
  • 18
1

NKAssetDownload does work on the iPad iOS 5.0 simulator but is not available on the iPad iOS 4.3 simulator. If you ran the app on the 4.3 simulator you would have got an error when you tried to access newsstandkit so I guess you used the 5.0 simulator.

Your code extract seems fine so this one will probably remain a mystery.

Martin Lockett
  • 2,275
  • 27
  • 31