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;
}