JSQMessagesViewController EXC_BAD_ACCESS添加位置

时间:2017-01-07 18:14:24

标签: ios objective-c exc-bad-access mkannotation jsqmessagesviewcontroller

我正在使用JSQMessagesViewController创建聊天应用。添加位置时,偶尔会在以下行中使用EXC_BAD_ACCESS崩溃。

MKAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier:nil];

在以下函数中:

- (void)createMapViewSnapshotForLocation:(CLLocation *)location
                    coordinateRegion:(MKCoordinateRegion)region
               withCompletionHandler:(JSQLocationMediaItemCompletionBlock)completion
{
NSParameterAssert(location != nil);

MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init];
options.region = region;
options.size = [self mediaViewDisplaySize];
options.scale = [UIScreen mainScreen].scale;

MKMapSnapshotter *snapShotter = [[MKMapSnapshotter alloc] initWithOptions:options];

[snapShotter startWithQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
          completionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
              if (snapshot == nil) {
                  NSLog(@"%s Error creating map snapshot: %@", __PRETTY_FUNCTION__, error);
                  return;
              }
              MKPointAnnotation* annotation= [MKPointAnnotation new];
              annotation.coordinate = [[[CLLocation alloc]initWithLatitude: 23.4 longitude: 53.2] coordinate];

              MKAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier:nil];
              CGPoint coordinatePoint = [snapshot pointForCoordinate:location.coordinate];
              UIImage *image = snapshot.image;

              coordinatePoint.x += pin.centerOffset.x - (CGRectGetWidth(pin.bounds) / 2.0);
              coordinatePoint.y += pin.centerOffset.y - (CGRectGetHeight(pin.bounds) / 2.0);

              UIGraphicsBeginImageContextWithOptions(image.size, YES, image.scale);
              {
                  [image drawAtPoint:CGPointZero];
                  [pin.image drawAtPoint:coordinatePoint];
                  self.cachedMapSnapshotImage = UIGraphicsGetImageFromCurrentImageContext();
              }
              UIGraphicsEndImageContext();

              if (completion) {
                  dispatch_async(dispatch_get_main_queue(), completion);
              }
            }];
      }

这是堆栈跟踪:

enter code here* thread #18: tid = 0x178725, 0x000000018b443aa8 UIKit`-[_UIViewAdditiveAnimationAction runActionForKey:object:arguments:] + 2720, queue = 'com.apple.root.default-qos', stop reason = EXC_BAD_ACCESS (code=1, address=0x90)
frame #0: 0x000000018b443aa8 UIKit`-[_UIViewAdditiveAnimationAction runActionForKey:object:arguments:] + 2720
frame #1: 0x0000000188604f34 QuartzCore`CA::Layer::set_bounds(CA::Rect const&, bool) + 404
frame #2: 0x00000001886050b4 QuartzCore`-[CALayer setBounds:] + 100
frame #3: 0x00000001915683b8 MapKit`-[MKLayer setBounds:] + 48
frame #4: 0x000000018b1aed18 UIKit`-[UIView(Geometry) setBounds:] + 400
frame #5: 0x0000000191568820 MapKit`-[MKAnnotationView setImage:] + 156
frame #6: 0x00000001915682f4 MapKit`-[MKPinAnnotationView initWithAnnotation:reuseIdentifier:] + 484
 * frame #7: 0x0000000100b6df40 JSQMessagesViewController`__96-[JSQLocationMediaItem createMapViewSnapshotForLocation:coordinateRegion:withCompletionHandler:]_block_invoke((null)=<unavailable>, snapshot=0x0000000170a2c760, error=0x0000000000000000) + 340 at JSQLocationMediaItem.m:111
frame #8: 0x00000001916fdb2c MapKit`__41-[MKMapSnapshotter _succeedWithSnapshot:]_block_invoke_2 + 84
frame #9: 0x000000010154d258 libdispatch.dylib`_dispatch_call_block_and_release + 24
frame #10: 0x000000010154d218 libdispatch.dylib`_dispatch_client_callout + 16
frame #11: 0x000000010155b26c libdispatch.dylib`_dispatch_queue_override_invoke + 980
frame #12: 0x000000010155ce2c libdispatch.dylib`_dispatch_root_queue_drain + 584
frame #13: 0x000000010155cb78 libdispatch.dylib`_dispatch_worker_thread3 + 140
frame #14: 0x000000018433f2a0 libsystem_pthread.dylib`_pthread_wqthread + 1288
frame #15: 0x000000018433ed8c libsystem_pthread.dylib`start_wqthread + 4

0 个答案:

没有答案