ios - Objective C: Download PDF and Open in iBooks -


i making app downloads file online server , save app's local memory. now, want when click "view pdf" button open pdf file directly ibooks.

here's code saving file:

        currenturl = @"http://weblink.com/folder1/folder2/file.pdf";         nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:currenturl]];          nsurlconnection *conn = [[nsurlconnection alloc] init];     (void)[conn initwithrequest:request delegate:self];      dispatch_queue_t queue = dispatch_get_global_queue(dispatch_queue_priority_high, 0ul);     dispatch_async(queue, ^{         data = [nsdata datawithcontentsofurl:[nsurl urlwithstring:currenturl]];         dispatch_sync(dispatch_get_main_queue(), ^{         });         resourcedocpath = [[nsstring alloc] initwithstring:[[[[nsbundle mainbundle]  resourcepath] stringbydeletinglastpathcomponent] stringbyappendingpathcomponent:@"documents"]];          filepath = [resourcedocpath stringbyappendingpathcomponent:@"mypdf.pdf"];         [data writetofile:filepath atomically:yes];     }); 

and here's found internet opening file ibooks (i put code on button click):

    nsstring *path = [[nsbundle mainbundle] pathforresource:@"mypdf" oftype:@"pdf"];     nsurl *url = [nsurl fileurlwithpath:path];     uidocumentinteractioncontroller *doccontroller = [[uidocumentinteractioncontroller alloc] init];      doccontroller = [uidocumentinteractioncontroller interactioncontrollerwithurl:url];     doccontroller.delegate = self; 

the app crashing code , message:

*** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '*** -[nsurl initfileurlwithpath:]: nil string parameter' 

compare filepath when write path when read. different me have invalid/nil reference in button click code.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -