iphone - How do I write my files to an NSBundle? -
i writing iphone/ipad app have zipped files come in contents of website can run upon extracting. put these files , folders single file i.e. nsbundle file can display user if single file , can deleted or moved not traversed. (my app allows traversal of folders throughout nsdocuments folder)
i know can import own nsbundle project , read website. @ possible write 1 using made directory structure files , folders must remain are, i.e. web folder described earlier?
if not nsbundle, can write(convert) folder other type of package?
if not, have other suggestions predicament
this not direct answer question, alternative way of looking @ problem.
specifically, you've stated app allows traversal of folders throughout nsdocumentdirectory. since code enumerating files/folders in there, implement enumeration code treats folders matching pattern (e.g. *.bundle) leaf nodes in hierarchy; user need never know there inside there.
-  
taking 1 step further, store .zip files directly in documents directory, provide contents directly uiwebview requests access individual urls.
it's possible register subclass of
nsurlprotocolgets first crack @ examining url requests. if subclass says can handle particular url (e.g. particular host or path), instance of subclass created , asked provide content.at point, can use zip-reading code, example objective-zip read requested file within zip, , return contents request.
use
nsurlprotocol +registerclass:register subclass system.in following example, protocol handler ignores requests, except site. returns same hard-coded string (as proof-of-concept):
myurlprotocolredirector.h:
#import <foundation/foundation.h> @interface myurlprotocolredirector : nsurlprotocol + (bool)caninitwithrequest:(nsurlrequest *)request; + (nsurlrequest *)canonicalrequestforrequest:(nsurlrequest *)request; - (void)startloading; - (void)stoploading; @endmyurlprotocolredirector.m:
#import "myurlprotocolredirector.h" @implementation myurlprotocolredirector + (bool)caninitwithrequest:(nsurlrequest *)request { if ([request.url.host compare:@"martinkenny.com"] == 0) { return yes; } return no; } + (nsurlrequest *)canonicalrequestforrequest:(nsurlrequest *)request { return request; } - (void)startloading { nsurlresponse *response = [[nsurlresponse alloc] initwithurl:self.request.url mimetype:@"text/plain" expectedcontentlength:11 textencodingname:nil]; [self.client urlprotocol:self didloaddata:[[nsdata alloc] initwithbytes:"hello world" length:11]]; [self.client urlprotocol:self didreceiveresponse:response cachestoragepolicy:nsurlcachestorageallowed]; [self.client urlprotocoldidfinishloading:self]; } - (void)stoploading { } @endsomeviewcontroller.m:
// register new url protocol handler system [nsurlprotocol registerclass:[myurlprotocolredirector class]]; uiwebview *webview = [[uiwebview alloc] initwithframe:self.view.bounds]; [webview loadrequest:[[nsurlrequest alloc] initwithurl:[nsurl urlwithstring:@"http://www.seenobjects.org/"]]]; [self.view addsubview:webview]; 
Comments
Post a Comment