ios - How to download a file from the webview in os x and save it to a specific location -
i have looked everywhere , have not found looking for, here question:
i have basic app playing around with. have created webview , able download file website loads in webview , save file downloads folder on local machine. site loads fine within webview, how download file, .xml file site , save downloads folder on local machine?
this have far:
- (void)applicationdidfinishlaunching:(nsnotification *)anotification { nsurl *url = [nsurl urlwithstring:@"http://www.google.com"];//<-- illustration site nsurlrequest *request = [nsurlrequest requestwithurl:url]; [[webview mainframe] loadrequest:request]; }
i able download file (possible using delegate) save location on local computer. pretty new i'd appreciate help.
the issue has been resolved. added next code create work:
- (void)applicationdidfinishlaunching:(nsnotification *)anotification { nsurl *url = [nsurl urlwithstring:@"http://www.google.com"]; // <-- illustration website nsurlrequest *request = [nsurlrequest requestwithurl:url]; self.webview.policydelegate = self; [self.webview setdownloaddelegate:self]; [[self.webview mainframe] loadrequest:request]; } - (void)webview:(webview *)webview decidepolicyformimetype:(nsstring *)type request:(nsurlrequest *)request frame:(webframe *)frame decisionlistener:(id < webpolicydecisionlistener >)listener { if([type isequaltostring:@"application/octet-stream"]) //this type looking { //figure out how save file here [listener download]; nsurldownload *download = [[nsurldownload alloc] initwithrequest:request delegate:self]; if(download) { [self download:download decidedestinationwithsuggestedfilename:@"filename.ext"]; nslog(@"file downloaded succesfully"); //[webview close]; [self.window close]; } else { nslog(@"the download failed"); } } //just ignore other types; default behaviour used } -(void)download:(nsurldownload *)download decidedestinationwithsuggestedfilename:(nsstring *)filename { nsstring *destinationfilename; nsstring *homedirectory = nshomedirectory(); destinationfilename = [[homedirectory stringbyappendingpathcomponent:@"documents"] stringbyappendingpathcomponent:filename]; [download setdestination:destinationfilename allowoverwrite:no]; //file beingness saved documents folder on local machine }
hope helpful else.
ios objective-c osx webview
No comments:
Post a Comment