Compatibility of regionThatFits functions in iOS 6

Source: Internet
Author: User

Yesterday, I found a mandatory scenario for the App. I tracked it and found the following statement:

[Cpp]
[Self. mapView setRegion: [self. mapView regionThatFits: theRegion] animated: NO];

The crash information is:
[Cpp]
* ** Terminating app due to uncaught exception 'nsinvalidargumentexception ', reason:
'Invalid Region <center: nan, nan span: nan, nan>'

However, the theRegion variable is valid when it fails, so the code is extracted for tracking:
[Cpp]
MKCoordinateRegion fitRegion = [self. mapView regionThatFits: theRegion];
[Self. mapView setRegion: fitRegion animated: NO];

Tracking found that the regionThatFits function will change the theRegion variable:
[Cpp]
(MKCoordinateRegion) theRegion = {
Center = {
Latitude = 30.849
Longpolling = 117.749
}
Span = {
LatitudeDelta = 0.01
LongitudeDelta = 0.01
}
}

Convert:
[Cpp]
(MKCoordinateRegion) fitRegion = {
Center = {
Latitude = nan
Longpolling = nan
}
Span = {
LatitudeDelta = nan
LongitudeDelta = nan
}
}

I am confused. I think of a classic programmer saying, "I used to run well ".
So I tried to change the device for iOS 5 and found that it was OK. It seems that it was a compatibility problem for iOS 6. So I ran the 4.3-6.0 simulator and found it was OK. This problem was caused only by the real chance of installing iOS 6.

 


So I made some temporary changes:

[Cpp]
MKCoordinateRegion fitRegion = [self. mapView regionThatFits: theRegion];
If (isnan (fitRegion. center. latitude )){
// IOS 6 will result in nan. 2012-10-15
FitRegion. center. latitude = theRegion. center. latitude;
FitRegion. center. longpolling = theRegion. center. longpolling;
FitRegion. span. latitudeDelta = 0;
FitRegion. span. longitudeDelta = 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.