ios - MKMapSnapshotter startWithCompletionHandler 从未调用过

标签 ios objective-c iphone mkmapsnapshotter

是否有任何原因导致 MKMapSnapshotter 的 startWithCompletionHandler 方法上的完成处理程序不会被回调? (甚至没有错误!!)

我没有做任何花哨的事情,只是抓取快照并显示它,全部在前台,没有后台处理。

不同寻常的是,它看起来完全是随机的,这意味着有时它工作得很好,而其他时候则永远不会。

这是我的代码:

MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init];
options.size = somePredeterminedSize;
options.scale = [[UIScreen mainScreen] scale];
options.mapType = MKMapTypeStandard;
options.region = MKCoordinateRegionMakeWithDistance(mycoordinate, 1000, 1000);

MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
[snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
    if (error) {
        NSLog(@"[Error] %@", error);
        return;
    }

    MKAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:nil reuseIdentifier:nil];
    pin.image = [UIImage imageNamed:@"map-pin"];
    UIImage *image = snapshot.image;
    UIGraphicsBeginImageContextWithOptions(image.size, YES, image.scale);
    [image drawAtPoint:CGPointMake(0.0f, 0.0f)];
    CGRect rect = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height);

    CGPoint point = [snapshot pointForCoordinate:self.bureau.coordinate];
    if (CGRectContainsPoint(rect, point)) {
        point.x = point.x + pin.centerOffset.x - (pin.bounds.size.width / 2.0f);
        point.y = point.y + pin.centerOffset.y - (pin.bounds.size.height / 2.0f);
        [pin.image drawAtPoint:point];
    }

    UIImage *compositeImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

}];

我已经在多台同时运行不同 iOS 版本的设备上进行了测试: 运行 iOS 8.4 的 iPhone 5S 运行 iOS 9.2 的 iPhone 6 运行 iOS 8.2 的 iPhone 6+

所有 3 台设备都连接到同一个 WIFI。 iPhone 6+ 几乎永远不会出故障,而 iPhone 6 几乎总是出故障。

有什么建议吗?

最佳答案

我遇到了同样的问题, 在我的应用程序中,我有一个包含一些 map 图像的地址列表,如果您按下图像,其中一个选项是在 map 应用程序中打开它。 在 iPhone 上,它完美地创建了图像,但在 iPad 上,直到我尝试在 Apple“ map ”应用程序(使用 MKMapItem.openMapsWithItems ...)中打开地址,它才打开了 map 应用程序并显示了一个警报权限,我按下“允许”,回到我的应用程序,它开始完美运行。

尝试打开 map 应用,允许权限,看看它是否适用于您的应用。

希望对您有所帮助。

关于ios - MKMapSnapshotter startWithCompletionHandler 从未调用过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35013530/

相关文章:

objective-c - NSPopover 的 contentViewController 中的动画变化

objective-c - 为什么 Objective-C 不支持私有(private)方法?

iphone - 保存到 CoreData - 添加到顶部

ios - 如何使用 Apple 提供的图标

iphone - "No provisioning iOS device connected"

ios - 无声推送通知与普通推送通知

ios - 从 html 链接重定向到 IOS 应用程序

iphone - Linea Pro 扫描条码问题

ios - "wrong orientation"中的 UIView 中心

ios - 二元运算符 '<<' 不能应用于两个 'T' 操作数