Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NKAssetDownload Download Issues

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!

like image 857
Johnny Avatar asked Oct 09 '22 01:10

Johnny


1 Answers

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.

like image 194
Johnny Avatar answered Oct 18 '22 12:10

Johnny