Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If your view controller really needs the location information before it is presented, it can have the presenting view controller perform the location services before the transition. If there is no presenting view controller (i.e. the view controller that needs the location is currently the root view controller), you can introduce a new root view controller which will perform the location services before transitioning to the main view controller.</p> <p>This presenting view controller should (per the Location Awareness Programming Guide) should create the <code>CLLocationManager</code>, initiate location services, and upon receiving the appropriate <code>didUpdateLocations</code> of the <code>CLLocationManagerDelegate</code>, it can then stop location services and transition to the main view controller. Perhaps this intermediate view controller should also show some nice "please wait" screen or a copy of the <code>default.png</code> image with a <code>UIActivityIndicatorView</code> while the location services are being performed.</p> <p>In practice, though, you don't necessarily need to introduce this intermediate view controller. You could do it all with your primary view controller. You can employ asynchronous event-driven coding patterns. So, rather than requiring the location before the view is presented, you can defer the performance of the web services until after the location services have been satisfied. For example, <a href="https://github.com/robertmryan/ios-wunderground-demo" rel="nofollow">this simple test project</a> invokes location services, and upon completion, submits a web request to a weather service, and parses the JSON response. No intermediate view controller was needed.</p> <p>Note, though, that Apple frowns upon (i.e. may well reject) apps that only work if the location services succeed, so you may want to think about what your app is supposed to do if it simply is unable to use location services. You must gracefully handle that scenario, perhaps use the last known location.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload