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 9246827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:35:02+00:00 2026-06-18T09:35:02+00:00

I am creating a new Traveling Application in iOS, this application is highly dependent

  • 0

I am creating a new Traveling Application in iOS, this application is highly dependent on Maps and will include two Maps.

  1. My first Map will work when the user has a strong Network Signal (Apple Maps).
  2. My second Map will be used when their isn’t any Network or really Low signal (Offline
    MapBox).

Why do I have two different maps in one Application? My Application is a Direction App, so when the user has really low network or none it will go to the offline Map MapBox. Also the Apple Maps will have Yelp integration and not the offline Map MapBox.

So my Question: How can I detect the network signal in WiFi, 4G Lte, and 3G.
MapBox Offline Image

  • 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-06-18T09:35:04+00:00Added an answer on June 18, 2026 at 9:35 am

    My original thought was to time the download of a file, and see how long it takes:

    @interface ViewController () <NSURLSessionDelegate, NSURLSessionDataDelegate>
    
    @property (nonatomic) CFAbsoluteTime startTime;
    @property (nonatomic) CFAbsoluteTime stopTime;
    @property (nonatomic) long long bytesReceived;
    @property (nonatomic, copy) void (^speedTestCompletionHandler)(CGFloat megabytesPerSecond, NSError *error);
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        [self testDownloadSpeedWithTimout:5.0 completionHandler:^(CGFloat megabytesPerSecond, NSError *error) {
            NSLog(@"%0.1f; error = %@", megabytesPerSecond, error);
        }];
    }
    
    /// Test speed of download
    ///
    /// Test the speed of a connection by downloading some predetermined resource. Alternatively, you could add the
    /// URL of what to use for testing the connection as a parameter to this method.
    ///
    /// @param timeout             The maximum amount of time for the request.
    /// @param completionHandler   The block to be called when the request finishes (or times out).
    ///                            The error parameter to this closure indicates whether there was an error downloading
    ///                            the resource (other than timeout).
    ///
    /// @note                      Note, the timeout parameter doesn't have to be enough to download the entire
    ///                            resource, but rather just sufficiently long enough to measure the speed of the download.
    
    - (void)testDownloadSpeedWithTimout:(NSTimeInterval)timeout completionHandler:(nonnull void (^)(CGFloat megabytesPerSecond, NSError * _Nullable error))completionHandler {
        NSURL *url = [NSURL URLWithString:@"http://insert.your.site.here/yourfile"];
    
        self.startTime = CFAbsoluteTimeGetCurrent();
        self.stopTime = self.startTime;
        self.bytesReceived = 0;
        self.speedTestCompletionHandler = completionHandler;
    
        NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration];
        configuration.timeoutIntervalForResource = timeout;
        NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
        [[session dataTaskWithURL:url] resume];
    }
    
    - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {
        self.bytesReceived += [data length];
        self.stopTime = CFAbsoluteTimeGetCurrent();
    }
    
    - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
        CFAbsoluteTime elapsed = self.stopTime - self.startTime;
        CGFloat speed = elapsed != 0 ? self.bytesReceived / (CFAbsoluteTimeGetCurrent() - self.startTime) / 1024.0 / 1024.0 : -1;
    
        // treat timeout as no error (as we're testing speed, not worried about whether we got entire resource or not
    
        if (error == nil || ([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorTimedOut)) {
            self.speedTestCompletionHandler(speed, nil);
        } else {
            self.speedTestCompletionHandler(speed, error);
        }
    }
    
    @end
    

    Note, this measures the speed including the latency of starting the connection. You could alternatively initialize startTime in didReceiveResponse, if you wanted to factor out that initial latency.


    Having done that, in retrospect, I don’t like spending time or bandwidth downloading something that has no practical benefit to the app. So, as an alternative, I might suggest a far more pragmatic approach: Why don’t you just try to open a MKMapView and see how long it takes to finish downloading the map? If it fails or if it takes more than a certain amount of time, then switch to your offline map. Again, there is quite a bit of variability here (not only because network bandwidth and latency, but also because some map images appear to be cached), so make sure to set a kMaximumElapsedTime to be large enough to handle all the reasonable permutations of a successful connection (i.e., don’t be too aggressive in using a low value).

    To do this, just make sure to set your view controller to be the delegate of the MKMapView. And then you can do:

    @interface ViewController () <MKMapViewDelegate>
    @property (nonatomic, strong) NSDate *startDate;
    @end
    
    static CGFloat const kMaximumElapsedTime = 5.0;
    
    @implementation ViewController
    
    // insert the rest of your implementation here
    
    #pragma mark - MKMapViewDelegate methods
    
    - (void)mapViewWillStartLoadingMap:(MKMapView *)mapView {
        NSDate *localStartDate = [NSDate date];
        self.startDate = localStartDate;
    
        double delayInSeconds = kMaximumElapsedTime;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            // Check to see if either:
            //   (a) start date property is not nil (because if it is, we 
            //       finished map download); and
            //   (b) start date property is the same as the value we set
            //       above, as it's possible this map download is done, but
            //       we're already in the process of downloading the next
            //       map.
    
            if (self.startDate && self.startDate == localStartDate)
            {
                [[[UIAlertView alloc] initWithTitle:nil
                                            message:[NSString stringWithFormat:@"Map timed out after %.1f", delayInSeconds]
                                           delegate:nil
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil] show];
            }
        });
    }
    
    - (void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error {
        self.startDate = nil;
    
        [[[UIAlertView alloc] initWithTitle:nil
                                    message:@"Online map failed"
                                   delegate:nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil] show];
    }
    
    - (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView
    {
        NSTimeInterval elapsed = [[NSDate date] timeIntervalSinceDate:self.startDate];
        self.startDate = nil;
        self.statusLabel.text = [NSString stringWithFormat:@"%.1f seconds", elapsed];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need UNION two tables with creating new field, where 1 for first table,
I'm creating new processes using System.Diagnostics.Process class from my application. I want this processes
When creating new class instance I get A first chance exception of type 'System.Deployment.Application.InvalidDeploymentException'
I'm creating new Site Definitions using this method: http://weblogs.asp.net/paulballard/archive/2007/04/09/creating-a-custom-sharepoint-2007-portal-site-definition-using-the-portalprovisioningprovider-class.aspx and when they get created,
This wizard appears when creating new android projects. I would like to change the
I have the below function creating new panels inside my ViewStack.. This works fine
I'm creating a program that will calculate he cost of traveling. Each segment has
I'm creating new application using zend framework with several modules. Can you please advice
I'm trying to make creating new instances with Tastypie work, but I keep getting
When creating new Rails app I get this error <internal:lib/rubygems/custom_require>:29:in `require': libcrypto.so.0.9.8: cannot open

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.