How to read a file from a website using objective-c & xcode

I am trying to write code that will capture some information provided by my server (remote), for example, request a URL that will return data that will be presented in the application after it is parsed.

I try from 2 days when I was looking for her, I found some kind of incomplete solution, but nothing worked for me

I'm really a noob in Xcode and Objective-C

thank

+3
source share
1 answer

Click for Apple URL download documentation. Especially interesting for you Using NSURLConnection.

: Framework ASIHTTP:

:

- (void)grabURL
{
  NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
  ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
  [request startSynchronous];
  NSError *error = [request error];
  if (!error) {
    NSString *response = [request responseString];
  }
}

:

- (void)grabURLInBackground
{
   NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
   ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
   [request setDelegate:self];
   [request startAsynchronous];
}

- (void)requestFinished:(ASIHTTPRequest *)request
{
   // Use when fetching text data
   NSString *responseString = [request responseString];

   // Use when fetching binary data
   NSData *responseData = [request responseData];
}

- (void)requestFailed:(ASIHTTPRequest *)request
{
   NSError *error = [request error];
}
+9

Source: https://habr.com/ru/post/1782110/


All Articles