MKMapSnapshotter completionHandler 从 WatchKit 调用时从未在父应用程序中调用 [英] MKMapSnapshotter completionHandler never called in parent app when called from WatchKit

查看:25
本文介绍了MKMapSnapshotter completionHandler 从 WatchKit 调用时从未在父应用程序中调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题:我像往常一样使用 openParentApplication:reply: 调用父应用程序.

I have this weird issue: I call the parent app with openParentApplication:reply: as normal.

使用异步 NSURLRequests 从 Internet 获取一些数据做得很好,但是当我想使用 MKMapSnapshotter 获取地图图像时(仍在父应用程序中)它的完成块永远不会被调用.

It is nicely doing its job getting some data from the internet using async NSURLRequests but when I want to get a map image using MKMapSnapshotter (still in the parent app) its completion block is never called.

MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
[snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
    NSLog(@"completion handler is called"); //this never called
};

我尝试调用:snapshotter startWithQueue:on dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)dispatch_get_main_queue() 等,但似乎没有工作.

I tried to call with: snapshotter startWithQueue:on dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0) or dispatch_get_main_queue() etc. but nothing seems to work.

如果我直接从 WKInterfaceController 或从父应用程序调用相同的代码,它工作得很好.

If I call the same code directly from WKInterfaceController or from the parent app it works just fine.

推荐答案

我认为您无法按照自己的意愿调用/使用 MKMapSnapshooter.当您使用 openParentApplication 发出请求时,它会在后台模式下打开您的父应用程序,并且 MKMapSnapshooter 需要前台模式来提供最终图像.

I don't think you can call/use MKMapSnapshooter the way you are wanting to. When you use openParentApplication to make the request, it is opening your parent app in background mode and MKMapSnapshooter requires Foreground mode to deliver the final image.

根据 Apple 文档:

as per Apple docs:

快照程序仅在您的应用程序完成时才将最终图像交付给您的应用程序在前台运行.快照程序必须渲染最终图像当您的应用程序在前台时.如果你开始生成一个应用程序在后台时的快照,或者如果您的应用程序移动到正在进行快照时的背景,此行为会延迟发送快照,直到您的应用返回前台.

The snapshotter delivers the final image to your app only when it is running in the foreground. The snapshotter must render the final image while your app is in the foreground. If you start generating a snapshot while the app is in the background, or if your app moves to the background while a snapshot is in progress, this behavior delays the delivery of the snapshot until your app returns to the foreground.

这篇关于MKMapSnapshotter completionHandler 从 WatchKit 调用时从未在父应用程序中调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆