当我尝试将半径添加到围栏应用程序时,出现[__NSCFNumber getCString:maxLength:encoding:]崩溃。
这是我的代码:

NSString *identifier = [dictionary valueForKey:@"id"];

CLLocationDegrees latitude = [[dictionary valueForKey:@"lat"] doubleValue];

CLLocationDegrees longitude =[[dictionary valueForKey:@"lon"] doubleValue];

CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(latitude, longitude);

CLLocationDistance regionRadius = [[dictionary valueForKey:@"radius"] doubleValue];
NSLog(@"nslog is %f",regionRadius);


if(regionRadius > _locationManager.maximumRegionMonitoringDistance)
{
    regionRadius = _locationManager.maximumRegionMonitoringDistance;
}

NSString *version = [[UIDevice currentDevice] systemVersion];
CLRegion * region =nil;

if([version floatValue] >= 7.0f) // for iOS > 7
{
    region =  [[CLCircularRegion alloc] initWithCenter:centerCoordinate
                                                radius:regionRadius
                                            identifier:identifier];
}
else // for iOS < 7
{
    region = [[CLRegion alloc] initCircularRegionWithCenter:centerCoordinate
                                                     radius:regionRadius
                                                 identifier:identifier];
}

这里的Stacktrace是
0   KNOXXi                              0x00064c8b -[KCSDK dictToRegion:] + 854
1   KNOXXi                              0x000640cf -[KCSDK addGeofence:] + 86
2   KNOXXi                              0x00065d25 __25-[KCSDK reloadLocations:]_block_invoke + 536
3   KNOXXi                              0x0006369d __59-[KCSDK fetchNearbyFencesWithLocation:withSuccess:failure:]_block_invoke + 196
4   KNOXXi                              0x0002762d __64-[AFHTTPRequestOperation setCompletionBlockWithSuccess:failure:]_block_invoke46 + 36
5   libdispatch.dylib                   0x3992f833 <redacted> + 10
6   libdispatch.dylib                   0x3992f81f <redacted> + 22
7   libdispatch.dylib                   0x3993649f <redacted> + 278
8   CoreFoundation                      0x2e7648a1 <redacted> + 8
9   CoreFoundation                      0x2e763175 <redacted> + 1300
10  CoreFoundation                      0x2e6cdebf CFRunLoopRunSpecific + 522
11  CoreFoundation                      0x2e6cdca3 CFRunLoopRunInMode + 106
12  GraphicsServices                    0x33601663 GSEventRunModal + 138
13  UIKit                               0x3101a14d UIApplicationMain + 1136
14  KNOXXi                              0x00026411 main + 224
15  libdyld.dylib                       0x39954ab7 <redacted> + 2

最佳答案

试试这个

NSString * identifier = [[字典valueForKey:@“id”] stringvalue];

关于ios - NSCFNumber getCString maxLength编码在创建地理围栏时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24670443/

10-11 00:31