Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 954601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:14:33+00:00 2026-05-16T00:14:33+00:00

my app is supposed to make a request from a server every 10 seconds

  • 0

my app is supposed to make a request from a server every 10 seconds or so with a specific url, change some attributes in the url, and then show the request in another view called “updateView” or if any network error occurred display the error. The first part works fine but if i switch of wifi for example the app crashes. How do i fix this and how do i display the various errors? Thanks in advance!! Here’s my code (this is the method which gets called every 10 seconds):

- (void)serverUpdate{
CLLocationCoordinate2D newCoords = self.location.coordinate;

gpsUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://odgps.de/chris/navextest?objectid=3&latitude=%2.4fN&longitude=%2.4fE&heading=61.56&velocity=5.21&altitude=%f&message=Eisberg+voraus%21", newCoords.latitude, newCoords.longitude, self.location.altitude]];

self.pageData = [NSString stringWithContentsOfURL:gpsUrl];


[updateView.transmissions insertObject:pageData atIndex:counter];
if (counter == 100) {
    [updateView.transmissions removeAllObjects];
    counter = -1;
}
counter = counter + 1;



    [updateView.tableView reloadData];
self.sendToServerSuccessful = self.sendToServerSuccessful + 1;
[self.tableView reloadData];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:14:33+00:00Added an answer on May 16, 2026 at 12:14 am

    First, you’re blocking the main thread while it waits for the network operation to complete when you call stringWithContentsOfURL: and that’s a bad thing because if the network is slow or unreachable, it’ll look like your app has crashed.

    Second, stringWithContentsOfURL: is deprecated and you should use this instead, even though it still blocks the main thread:

    self.pageData = [NSString stringWithContentsOfURL:gpsURL encoding:NSUTF8StringEncoding error:nil];
    

    You should be using NSURLConnection to download the data without blocking the main thread. Create a NSURLRequest from the URL, pass it to [NSURLConnection connectionWithRequest:request delegate:self]; which starts the URL connection.

    Here’s some code for the NSURLConnection delegate:

    - (void)connection:(NSURLConnection *)aConnection didReceiveResponse:(NSURLResponse *)response {
        if ([response isKindOfClass: [NSHTTPURLResponse class]]) {
            statusCode = [(NSHTTPURLResponse*) response statusCode];
            /* HTTP Status Codes
                200 OK
                400 Bad Request
                401 Unauthorized (bad username or password)
                403 Forbidden
                404 Not Found
                502 Bad Gateway
                503 Service Unavailable
             */
        }
        self.receivedData = [NSMutableData data];
    }
    
    - (void)connection:(NSURLConnection *)aConnection didReceiveData:(NSData *)data {
        [self.receivedData appendData:data];
    }
    
    - (void)connectionDidFinishLoading:(NSURLConnection *)aConnection {
        // Parse the received data
        [self parseReceivedData:receivedData];
        self.receivedData = nil;
    }   
    
    - (void)connection:(NSURLConnection *)aConnection didFailWithError:(NSError *)error {
        statusCode = 0; // Status code is not valid with this kind of error, which is typically a timeout or no network error.
        self.receivedData = nil;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I make a change to a javascript or jsp file while my app
I am writing an app where I am supposed to make a user to
I am trying to make an android app that retrieves info from google app
I have a demo app which is supposed to be an example of creating
In an N-Tier app you're supposed to have a business logic layer and a
I have a python app which is supposed to be very long-lived, but sometimes
I've got an iPhone App that is supposed to send POST data to my
This app displays a form with a textbox where the user is supposed to
In my app, the user is supposed to insert a phone number, which is
I am creating a SMS app the following code is supposed to: check if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.