Search Results

Search found 175 results on 7 pages for 'nsurlrequest'.

Page 2/7 | < Previous Page | 1 2 3 4 5 6 7  | Next Page >

  • Download a file using cocoa

    - by dododedodonl
    Hi All, I want to download a file to the downloads folder. I searched google for this and found the NSURLDownload class. I've read the page in the dev center and created this code (with some copy and pasting) this code: @implementation Downloader @synthesize downloadResponse; - (void)startDownloadingURL:(NSString*)downloadUrl destenation:(NSString*)destenation { // create the request NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:downloadUrl] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; // create the connection with the request // and start loading the data NSURLDownload *theDownload=[[NSURLDownload alloc] initWithRequest:theRequest delegate:self]; if (!theDownload) { NSLog(@"Download could not be made..."); } } - (void)download:(NSURLDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename { NSString *destinationFilename; NSString *homeDirectory=NSHomeDirectory(); destinationFilename=[[homeDirectory stringByAppendingPathComponent:@"Desktop"] stringByAppendingPathComponent:filename]; [download setDestination:destinationFilename allowOverwrite:NO]; } - (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error { // release the connection [download release]; // inform the user NSLog(@"Download failed! Error - %@ %@", [error localizedDescription], [[error userInfo] objectForKey:NSErrorFailingURLStringKey]); } - (void)downloadDidFinish:(NSURLDownload *)download { // release the connection [download release]; // do something with the data NSLog(@"downloadDidFinish"); } - (void)setDownloadResponse:(NSURLResponse *)aDownloadResponse { [aDownloadResponse retain]; [downloadResponse release]; downloadResponse = aDownloadResponse; } - (void)download:(NSURLDownload *)download didReceiveResponse:(NSURLResponse *)response { // reset the progress, this might be called multiple times bytesReceived = 0; // retain the response to use later [self setDownloadResponse:response]; } - (void)download:(NSURLDownload *)download didReceiveDataOfLength:(unsigned)length { long long expectedLength = [[self downloadResponse] expectedContentLength]; bytesReceived = bytesReceived+length; if (expectedLength != NSURLResponseUnknownLength) { percentComplete = (bytesReceived/(float)expectedLength)*100.0; NSLog(@"Percent - %f",percentComplete); } else { NSLog(@"Bytes received - %d",bytesReceived); } } -(NSURLRequest *)download:(NSURLDownload *)download willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse { NSURLRequest *newRequest=request; if (redirectResponse) { newRequest=nil; } return newRequest; } @end But my problem is now, it doesn't appear on the desktop as specified. And I want to put it in downloads and not on the desktop... What do I have to do?

    Read the article

  • strange multiple files download - NSURLConnection

    - by Georg
    hi all, I encounter a problem by following your comment. I would like to download different file at same time with different delegate: .h: NSMutableData *fileData; .m: NSString *imgfile = [NSString stringWithFormat:@"http://xxxx/01.jpg"]; NSURL *fileURL1 = [NSURL URLWithString:imgfile]; NSString *audiofile = [NSString stringWithFormat:@"http://xxxx/01.mp3"]; NSURL *fileURL2 = [NSURL URLWithString:audiofile]; NSURLRequest *request1 = [NSURLRequest requestWithURL:fileURL1 cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0 ]; NSURLRequest *request2 = [NSURLRequest requestWithURL:fileURL2 cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0 ]; NSArray *connections = [[NSArray alloc] initWithObjects: [[NSURLConnection alloc] initWithRequest:request1 delegate:self ], [[NSURLConnection alloc] initWithRequest:request2 delegate:self ], nil]; - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { fileData = [[NSMutableData alloc] init]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [fileData appendData:data]; } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { NSLog(@"Unable to fetch data"); } ok, the download process works, but, the file size of jpg and mp3 are incorrect, the only correct thing is the total file size (jpg+mp3), please could you have a look on the code, what is missing? Another question is, I put the file in a NSMutableArray, my question is, how to check which index of array is the correct file type (jpg and mp3)? because I need to save them to the device folder.

    Read the article

  • iphone download several files

    - by Floo
    hi all !  In my app i need to download several plist.  to download a plist i use the NSURLconnection  in my code i use an UIAlertView with a UIActivityIndicator then when the download is finished i add a button to the alert to dismiss it.  To download the plist i use somewhere in my code an NSURL set to the adresse where the plist is, next i set a NSURLRequest with the url cache policy and a timeout interval.  Then i set my NSMutableData to the NSURL connection with a NSURLRequest.  In the delegate didReceiveData: i append data to my mutable data object, in the didFailWithError: i handle error. And finaly in the connectionDidFinishLoading  i serialize my data to a plist so i can write to file my plist, and release my alertview.  My problem is : how can i do if i have sevetal file to download because the connectionDidFinishLoading is called each time my NSURLConnection is finished but i want to release my UiAlert when everything is finished. But when the first plist is downloaded my code in the connectionDidFinishLoading will fire.  here is my code :  in the view did load :  // set the UiAlert in the view did load  NSURL *theUrl = [NSURL URLWithString:@"http://adress.com/plist/myPlist.plist"]; NSURLRequest *theRequest = [NSURLRequest requestWithURL:theUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; self.plistConnection = [[ NSURLConnection alloc] initwithRequest:theRequest delegate:self startImmediatly:YES]; //plistConnection is a NSURLConnection - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {  [incomingPListData appendData:data]; } -(void)connection:(NSURLConnection *)connectionDidFailWithError:(NSError *)error { // handle error here  } -(void)connectionDidFinisloading:(NSURLConnection *) connection {  NSPropertyListFormat format; NSString *serialErrorString;  NSData *plist = [NSPropertyListSerialisation propertyListFromData:incomingPlistData mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&serialErrorString]; if (serialErrorString) {//error} else { // create path and write plist to path} // change message and title of the alert so if i want todownload an another file  where do i put the request the connection and how can i tell the didFinishLoading to fire code when all my file are downloaded.  thanks to all

    Read the article

  • I'm writing a diagnostic app for iOS that loads a predetermined set of webpages and records the time it takes for the page to render on the device.

    - by user1754840
    I'm writing a sort of diagnostic app for iOS that opens a predetermined list of websites and records the elapsed time it takes each to load. I have the app open a UIWebView within a ViewController. Here are the important bits of the ViewController source: - (void)viewDidLoad { [super viewDidLoad]; DataClass *obj = [DataClass getInstance]; obj.startOfTest = [NSDate date]; //load the first webpage NSString *urlString = [websites objectAtIndex:obj.counter]; //assume firstWebsite is already instantiated and counter is initially set to zero obj.counter = obj.counter + 1; NSURL *url = [NSURL URLWithString:urlString]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [obj.websiteStartTimes addObject:[NSDate date]]; [webView loadRequest:request]; } - (void)webViewDidFinishLoading:(UIWebView *)localWebView{ DataClass *obj = [DataClass getInstance]; //gets 'global' variables if(!webView.loading){ NSString *urlString = [websites objectAt:obj.counter]; obj.counter = obj.counter + 1; NSURL *url = [NSURL URLWithString:urlString]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [obj.websiteStartTimes addObject:[NSDate date]]; [webView loadRequest:request]; } The problem with this code is that it seems to load the next website before the one before it has finished. I would have thought that both the call to webViewDidFinishLoading AND the if statement within that would ensure that the website would be done, but that's not the case. I've noticed that sometimes, a single website will invoke the didFinishLoading method more than once, but it would only enter the if statement once. For example, if I have a list of ten websites, the webView would only really show the 3rd and the 6th website on the list and then indicate that it was "done" rendering them all. What else can I do to ensure that a website is done loading completely and rendered to the screen before the app moves on to the next one?

    Read the article

  • How do I display a local html file in a UIWebView?

    - by Thomas
    I have a relatively simple question that I cannot seem to find the answer for. While doing the Google Maps Java API Tutorials, I ran into a problem. I can load an HTML file from the web, but when I try it locally, it just displays the contents of the file instead of running the script. Here's what works: NSString *url = @"http://code.google.com/apis/maps/documentation/v3/examples/geocoding-simple.html"; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; [webView loadRequest:request]; I want to store the HTML file locally and run it from the device itself, so I tried: [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"geocoding-simple" ofType:@"html"]isDirectory:NO]]]; and it just displayed the contents of the file. What am I doing wrong here? Thomas

    Read the article

  • UIWebView Loading content properly on iOS 6 simulator but not on device?

    - by David Hegner
    I have encountered a weird bug with a released app. My UIWebView is no longer loading content on iOS 6, yet the content still displays in the simulator. The activity indicator displays properly but then it loads a blank url? Again, this only happens on a device, not on the simulator. To provide extra context (in the simulator the NSURLRequest is assigned the proper URL. When run on a device the value is nil.) Here is my code : -(void)loading { if(!self.webView.loading) [self.activityIndicator stopAnimating]; else { [self.activityIndicator startAnimating]; } } - (void)viewDidLoad { [self.webView addSubview:self.activityIndicator]; NSURLRequest *requestUrl = [NSURLRequest requestWithURL:self.url]; [self.webView loadRequest:requestUrl]; self.timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(loading) userInfo:nil repeats:YES]; [super viewDidLoad]; NSLog(@"%@", requestUrl); }

    Read the article

  • IPad App Issue - Webview

    - by Manoj Khaylia
    Hi all I developing a Ipad application I am trying to use Webview but not able to open the URL in webview I am using following code NSURL *fileURL = [[[NSURL alloc] initWithString:@"http://www.google.com/"] autorelease]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:fileURL]; [webview loadRequest:requestObj]; this code working well for Iphone app not not working for Ipad app. Is anything wrong. Thanks Amit Battan

    Read the article

  • NSURLConnectionDelegate connection:didReceiveData not working

    - by Shibin Moideen
    Hi All, I need some help regarding the NSURLConnectionDelegate method. - (void)startDownload { NSString *URLString = [NSString stringWithFormat:appRecord.imageURLString]; NSURL *url = [NSURL URLWithString:URLString]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; imageConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; if(imageConnection) { activeDownload = [NSMutableData data]; } } I am using this method to initiate the NSURLConnection, but the - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data is not calling.. Need Help Thanks in advance, Shibin

    Read the article

  • How to use NSURLDownload

    - by marshluca
    - (IBAction)startDownloadingURL:(id)sender { // create the request NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/index.html"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; // create the connection with the request // and start loading the data NSURLDownload *theDownload=[[NSURLDownload alloc] initWithRequest:theRequest delegate:self]; if (!theDownload) { // inform the user that the download could not be made } } when i run the simulator , i got an error: NSURLDownload undeclared ,first use in this fuction. where can i import the library of NSURLDownload.

    Read the article

  • willSendRequest redirectResponse doesn't work in iPhone SDK2.0

    - by WholeIphone
    I use the delegate method connection:willSendRequest:redirectResponse: in SDK 2.2, the code like below: - (NSURLRequest *)connection:(NSURLConnection *)con willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse { if(redirectResponse) { if(!self.autoRedirect) { NSLog(@"response will redirect"); request = nil; } } return request; if the request is returned to nil ,it seems it hangs up here, and delegate didReceiveData will not get called. but it works in SDK 3. Any suggestions about this?

    Read the article

  • How to write UIWebView with default request address is like (192.168.1.1)..

    - by user323503
    i have implemented UIWebView in my application but i default address is "192.168.1.1" but it is not open default it and i have tried with "http://www.google.com" it is working fine. [iview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"192.168.1.1"]]]; it doesn't working and it is working with [iview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];

    Read the article

  • Can't change background for UIWebView in iPhone SDK

    - by leon
    Hi, Is there a way to change background color for UIWebView? None of the colors set in IB effect UIWebView behavior: before acctual content is loaded it shows as up as white (causing a white flash between the moment it is loaded and content is rendered). Setting background color programmatically does not do anything either. Here is code: @interface Web_ViewViewController : UIViewController { UIWebView *web; } @property (nonatomic, retain) IBOutlet UIWebView *web; @end .... (void)viewDidLoad { super viewDidLoad; web.backgroundColor = UIColor blueColor; NSURL *clUrl = NSURL URLWithString:@"http://www.apple.com" ; NSURLRequest *req = NSURLRequest requestWithURL:clUrl; web loadRequest:req; } thanks

    Read the article

  • iPhone SDK : UIWebView detect link on textfeild !

    - by Momeks
    Hi i create simple web browser for my app and i don't know why when user click a link the address bar doesn't change as link address here is my code : -(IBAction)webAddress:(id)sender { [site loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[webAdress text]]]]; [webAdress resignFirstResponder]; } - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { //CAPTURE USER LINK-CLICK. if (navigationType == UIWebViewNavigationTypeLinkClicked) { NSURL *URL = [request URL]; if ([[URL scheme] isEqualToString:@"http"]) { [webAdress setText:[URL absoluteString]]; [self webAddress:nil]; } return NO; } return YES; } what's my problem ?

    Read the article

  • Stopping network activity indicator.

    - by iSharreth
    I used the below code to load a webpage. Everything works fine, but I want to stop the network activity indicator after completing loading the webpage. How can we know that the webpage is loaded completely. Anyone please help. UIApplication* app = [UIApplication sharedApplication]; app.networkActivityIndicatorVisible = YES; // to stop it, set this to NO NSURL *url = [NSURL URLWithString:@"http://www.google.com"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [webView loadRequest:request];

    Read the article

  • Correct way to load image into UIWebView from NSData object

    - by rustyshelf
    I have downloaded a gif image into an NSData object (I've checked the contents of the NSData object and it's definitely populated). Now I want to load that image into my UIWebView. I've tried the following: [webView loadData:imageData MIMEType:@"image/gif" textEncodingName:nil baseURL:nil]; but I get a blank UIWebView. Loading the image from the same URL directly works fine: NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:imageUrl]]; [imageView loadRequest:request]; Do I need to set the textEncodingName to something, or am I doing something else wrong? I want to load the image manually so I can report progress to the user, but it's an animated gif, so when it's done I want to show it in a UIWebView. Edit: Perhaps I need to wrap my image in HTML somehow? Is there a way to do this without having to save it to disk?

    Read the article

  • Anti-aliasing not working when resizing a UIWebView

    - by nickcartwright
    I'd like to add a Web View to my app at 60% scale (like seen in Safari in the browse other windows view): Notice how the content looks nice and Aliased! If I try and add the same Web view to my app: NSURL *url = [NSURL URLWithString:@"http://www.google.co.uk?q=hello"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)]; webView.delegate=self; [webView loadRequest:request]; [self.view addSubview:webView]; Using the following transformation: [webView setTransform:CGAffineTransformMakeScale(0.6, 0.6)]; ..the scale is really bad quality and there appears to be no anti-aliasing. Does anyone know why this is happening or have a suggestion on how it could be fixed? Thanks! Nick.

    Read the article

  • objective-c EXC_BAD_ACCESS in my code...

    - by Mark
    I'm new to objective-c and Im trying to write a little sample app that gets some XML from a remote server and outputs it to the console, but when I do it I get a EXC_BAD_ACCESS which I dont understand: NSString *FeedURL = @"MYURLGOESHERE"; NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:FeedURL]]; NSURLResponse *resp = nil; NSError *err = nil; NSData *response = [NSURLConnection sendSynchronousRequest: theRequest returningResponse: &resp error: &err]; NSString *theString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; NSLog(@"Response: %@", theString);]; [resp release]; [err release]; When I comment out the [resp release] line I dont get it anymore, can someone please explain this to me :) Thanks

    Read the article

  • nsstring - out of scope

    - by alexeyndru
    -(void)loadWebAdress:(NSString*)textAdress { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; adressurl=[NSString stringWithFormat:@"http://%@", textAdress]; NSURL *url=[NSURL URLWithString:adressurl]; NSURLRequest *requestObj=[NSURLRequest requestWithURL:url]; [webview loadRequest:requestObj]; } although url takes it's value from adressurl, adressurl is all the time out of scope when checked in debugger. what is going on? i would like to use it in some other places too. not only in this method. because is out of scope, the app crashes. But, I repeat, it is the one who gives its value to url.

    Read the article

  • passing user from UITableView to UIWebView based on selection

    - by ct2k7
    Hello, I'm trying to pass the user on to the interface based on their cell selection in the UITableView, ie, if the user selects cell 1, they are taken to view model 2, containing UIWebView. UIWebView then displays local file, cell1.html. Currently, I've manage to get placeholder using: selectedCellText.text = selectedCell; to display the name of the cell selected. How do I get it to directly pass to the UIWebView, stick UIWebView in the interface and link it using: UIWebView *myWebView = [[UIWebView alloc] initWithFrame:frame]; NSBundle *mainBundle = [NSBundle mainBundle]; NSString *stringUrl = [mainBundle pathForResource:@"selectedCell" ofType:@"html"]; NSURL *baseUrl = [NSURL fileURLWithPath:stringUrl]; NSURLRequest *urlRequest = [NSURLRequest requestWithURL:baseUrl]; [myWebView loadRequest:urlRequest]; My other issue is that some of the cell names have spaces in them, and for simplicity, I'd like to ensure that there are no spaces (actually, will it even work with spaces in the name, I assume with %20 ? Thanks

    Read the article

  • webViewDidFinishLoad exception

    - by Nava Carmon
    Hi, I have a screen with a webView in my navigation controller stack and when I navigate from this view back to a previous before the page completely loaded I get a EXCEPTION_BAD_ACCESS. Seems, that the view with a webView being released before it comes to webViewDidFinishLoad function. My question is how to overcome this problem? I don't expect from the user to wait till the page loads... The code is very simple: - (void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSURL *url = [NSURL URLWithString:storeUrl]; //URL Requst Object NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; //Load the request in the UIWebView. [browser loadRequest:requestObj]; } TIA

    Read the article

  • loading and formating the rtf file in uiwebview

    - by Jayshree
    Hello everybody. I am trying to load the contents of a rtf file in the uiwebview. I am successful in loading the contents, but it is unformatted. the fonts are too large and it doesnt have any format. it displays the color of the rtf content, but not the font or size. So what should i do now. is there anyother way to load the rtf and format it???? I load the rtf in following way: NSString *path = [[NSBundle mainBundle] pathForResource:@"Home" ofType:@"rtf"]; NSURL *url=[NSURL fileURLWithPath:path]; NSURLRequest *req=[NSURLRequest requestWithURL:url]; [menuWeb loadRequest:req]; So what should i do now. can anybody help me????

    Read the article

  • iPhone Google Maps KML Search

    - by satyam
    I'm using Google maps with KML Query. But my query string is "Japanese" string "??????" I'm using http://maps.google.co.jp. When requesting data, I'm getting "0" bytes. But the same query when I put in browser, its download a KML file. My code is as follows: query = [NSString stringWithFormat:@"http://maps.google.co.jp/maps?&near=%f,%f&q=??????&output=kml&num=%d", lat,lon, num]; NSURL* url = [NSURL URLWithString:query]; NSURLRequest* request = [NSURLRequest requestWithURL:url]; NSLog(@"Quering URL = %@", url); NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] autorelease]; NSData *myData = [NSURLConnection sendSynchronousRequest:request returningResponse: &response error: nil ]; NSInteger errorcode = [response statusCode]; I'm receiving "myData" with 0 bytes. why?

    Read the article

  • Why release the NSURLConnection instance in this statement?

    - by aquaibm
    I read this in a book. -(IBAction) updateTweets { tweetsView.text = @""; [tweetsData release]; tweetsData = [[NSMutableData alloc] init]; NSURL *url = [NSURL URLWithString:@"http://twitter.com/statuses/public_timeline.xml" ]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL: url]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; [connection release]; [request release]; [activityIndicator startAnimating]; } In this statement,is that correct to release the "connection" instance at that time? After releasing it which means this NSURLConnection instance will be destroyed since it's reference count is 0 ,how are we going to make this connection operation work? THANKS.

    Read the article

  • hiding network activity indicator

    - by iSharreth
    - (void)viewWillAppear:(BOOL)animated { app = [UIApplication sharedApplication]; app.networkActivityIndicatorVisible = YES; NSURL *url = [NSURL URLWithString:@"http://www.google.com"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [webView loadRequest:request]; } -(void)webViewDidFinishLoad { app.networkActivityIndicatorVisible = NO; } I want to hide the network activity indicator after webpage is loaded. I had written the above code. But the indicator is not hiding after the webpage is fully loaded. Anyone please help.

    Read the article

  • WebKitErrorDomain error 101

    - by Nam Young-jun
    The following code produces and error of: WebKitErrorDomain error 101 code: -(Void) searchBarSearchButtonClicked: (UISearchBar *) activeSearchBar { NSString * query = [searchBar.text stringByReplacingOccurrencesOfString: @ "" withString: @ "+"]; NSURL * url = [NSURL URLWithString: [NSString stringWithFormat: @ "http://http://www.google.com/search?q =%, query]]; NSURLRequest * requestObj = [NSURLRequest requestWithURL: url]; [Home loadRequest: requestObj]; } -(Void) loadView { [Super loadView]; CGRect bounds = [[UIScreen mainScreen] applicationFrame]; searchBar = [[UISearchBar alloc] initWithFrame: CGRectMake (0.0, 0.0, bounds.size.width, 48.0)]; searchBar.delegate = self; [Self.view addSubview: searchBar]; } I don't speak english and rely on a translator. Because of the language issue could this be a keyboard problem, or an encoding problem?

    Read the article

< Previous Page | 1 2 3 4 5 6 7  | Next Page >