Wednesday, 25 January 2012

Naming downloaded File


here code downloading mp3 shown in table view:
code:
downloadaction:^ {           rssentry *entry = [_allentries objectatindex:indexpath.row];                      self.nameit = entry.articletitle;           nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);                      nsstring *documentsdirectory = [paths objectatindex:0];           nsstring *pdfpath = [documentsdirectory stringbyappendingpathcomponent:[nameit stringbyappendingstring:@".mp3"]];           bool fileexists = [[nsfilemanager defaultmanager] fileexistsatpath:pdfpath];                      if (fileexists) {               nslog(@"you got 1 dummy!");               uialertview *ditto = [[uialertview alloc] initwithtitle:@"already downloaded" message:@"you have downloaded sermon." delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil];               [ditto show];               [ditto release];               [tableview deselectrowatindexpath:indexpath animated:yes];                           }           if (!fileexists) {                              if (downloadinprogress) {                   uialertview *inprogress = [[uialertview alloc] initwithtitle:@"busy" message:@"please let previous download finish before starting another." delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil];                   [inprogress show];                   [inprogress release];                   [tableview deselectrowatindexpath:indexpath animated:yes];                                   }               if (!downloadinprogress) {                   rssentry *entry = [_allentries objectatindex:indexpath.row];                                      self.nameit = entry.articletitle;                   nsurl *url = [nsurl urlwithstring:entry.articleurl];                       nsurlrequest *therequest = [nsurlrequest requestwithurl:url cachepolicy:nsurlrequestreloadignoringlocalcachedata timeoutinterval:60];                   __block nsurlconnection *connection = [nsurlconnection connectionwithrequest:therequest delegate:self];                                      uiapplication *application = [uiapplication sharedapplication]; //get shared application instance                                      __block uibackgroundtaskidentifier background_task; //create task object                                      background_task = [application beginbackgroundtaskwithexpirationhandler: ^ {                       // code gets called when app has been running in background long , os decides kill                       // might want cancel connection in case, way won't receive delegate methods longer.                       [connection cancel];                       [application endbackgroundtask: background_task]; //tell system done tasks                       background_task = uibackgroundtaskinvalid; //set task invalid                                              //system shutting down app @ point in time                   }];                                      self.backgroundtaskidentifier = background_task;                   if (connection) {                       receiveddata = [[nsmutabledata data] retain];                       self.thetable = tableview;                       self.thepath = indexpath;                   }                   else {                       uialertview *cancelled = [[uialertview alloc] initwithtitle:@"download failed" message:@"please check network settings, , retry download." delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil];                       [cancelled show];                       [cancelled release];                   }               }           }                  }
i have set check if file exists, , if download in progress, , if neither true, downloads. problem if during download click row, , warning wait until current download finished, still names original mp3 name of 2nd clicked row. ideas how can keep happening?
 



Forums iPhone, iPad, and iPod Touch iOS Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

No comments:

Post a Comment