You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于MapBox SDK的首个iOS应用定位异常求助

Fix: Mapbox iOS SDK Shows Wrong Location (Ghana/Togo Border) with HTTP Error -999

Hey there, I see you're running into a common snag when getting started with Mapbox's iOS SDK. The Ghana/Togo border is Mapbox's default fallback location when map tiles fail to load, and the -999 error (which maps to NSURLErrorCancelled) tells us the tile requests are being blocked or cancelled. Let's walk through targeted fixes step by step:

1. Double-Check Your Access Token

  • First, confirm the MGLMapboxAccessToken in your Info.plist is an exact match for the token you generated in the Mapbox dashboard—no extra spaces, typos, or line breaks allowed.
  • Head to your Mapbox account and verify the token is a public access token (the default type when you create one) and hasn't been restricted by IP or other filters (new tokens usually don't have restrictions, but it's worth double-checking).

2. Fix App Transport Security (ATS) Settings

iOS 9+ enforces ATS by default, which can interfere with Mapbox's tile requests even though they use HTTPS. Here's how to configure it properly:

  • Open your Info.plist and add this configuration (either via the property list editor or raw XML):
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>mapbox.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
    </dict>
</dict>
  • For quick testing, you can temporarily set NSAllowsArbitraryLoads to YES under NSAppTransportSecurity, but avoid this in production apps.

3. Clear Simulator Cache & Reset the App

The WAL file recovery log in your console suggests corrupted cache data might be causing issues:

  • Delete your app from the simulator (long-press the app icon → tap the "X" to delete).
  • For a thorough reset, go to Simulator → Reset Content and Settings... to wipe all simulator data, then rebuild and run your app.

4. Verify CocoaPods Installation & SDK Version

You're using Mapbox-iOS-SDK ~> 3.7, an older 2017-era version that might have compatibility issues with Xcode 9.2:

  • Run pod deintegrate in your project directory, delete the Podfile.lock file, then run pod install again to ensure a clean installation.
  • Try upgrading to the latest patch version compatible with Xcode 9.2 (like ~> 3.7.1) to rule out version-specific bugs.

5. Confirm MGLMapView IBOutlet Connection

While your code looks correct, it's worth ruling out a broken connection:

  • In Storyboard, right-click your ViewController and check the Connections panel to make sure viewMapBox is properly linked to the MGLMapView in your layout.
  • Add a debug print in viewDidLoad: print("Map view:", viewMapBox)—if it prints nil, you'll need to re-establish the IBOutlet connection.

Why This Happens

The -999 error means Mapbox's tile requests are being cancelled, usually due to network restrictions (ATS), an invalid access token, or corrupted cache. The fallback to the Ghana/Togo border is Mapbox's way of indicating it couldn't load the requested map tiles.

内容的提问来源于stack exchange,提问作者jingo_man

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:19:37