简体   繁体   English

iOS 9 MKTileOverlay无法正常工作

[英]iOS 9 MKTileOverlay not working

My app works fine on iOS 8, but when I tried to build it on Xcode 7, the map doesn't show. 我的应用程序在iOS 8上运行良好,但是当我尝试在Xcode 7上构建它时,地图未显示。 I tried it on simulator and real device. 我在模拟器和真实设备上尝试过。

Below is some code. 下面是一些代码。

 - (void)viewDidLoad { [super viewDidLoad]; NSString *url = [[NSUserDefaults standardUserDefaults] stringForKey:@"tileOverlayURL"]; MKTileOverlay *overlay = [[MKTileOverlay alloc] initWithURLTemplate:url]; overlay.canReplaceMapContent = YES; [self.mapView addOverlay:overlay level:MKOverlayLevelAboveLabels]; } #pragma mark - MKMapViewDelegate - (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay { if ([overlay isKindOfClass:[MKTileOverlay class]]) { return [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay]; } return nil; } 

I had the same problem. 我有同样的问题。 IOS 9 by default does not allow connecting to non secured URLs. 默认情况下,IOS 9不允许连接到不安全的URL。 The map servers I was using were non secured, so IOS 9 prevented the NSURLRequest that my code invoked in MkTileOverlay from talking to the map servers. 我使用的地图服务器是不安全的,因此IOS 9阻止了我的代码在MkTileOverlay中调用的NSURLRequest与地图服务器通信。

You can tell IOS 9 to allow access to these non secured servers. 您可以告诉IOS 9允许访问这些不受保护的服务器。 You must add an NSAppTransportSecurity section to your IOS project's info.plist file and specify an NSExceptionDomain for each non secure map server that you talk to. 您必须将NSAppTransportSecurity部分添加到IOS项目的info.plist文件中,并为与之交谈的每个非安全地图服务器指定一个NSExceptionDomain。 Here is an example showing 2 of the map servers that I use. 这是显示我使用的2个地图服务器的示例。

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>nationalmap.gov</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
        <key>opencyclemap.org</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
    </dict>
</dict>

I had the same problem with loading tiles in custom overlay. 我在自定义叠加层中加载图块时遇到了同样的问题。 My problem was that I was using "http" requests instead of "https". 我的问题是我使用的是“ http”请求而不是“ https”。 Requests with "http" are considered to be insecure on iOS9 and are blocked by default. 在iOS9上,带有“ http”的请求被认为是不安全的,并且默认情况下被阻止。 That could be possible issue. 那可能是个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM