Xcode9.2下Objective-C项目无法安装MapboxNavigation Pod求助
Hey there, sorry to hear you're hitting a snag installing MapboxNavigation in your Objective-C project on Xcode 9.2—let's break down what's going on and fix this step by step. Since your Swift project works perfectly, the issue almost certainly boils down to compatibility gaps between newer MapboxNavigation versions, Xcode 9.2's Swift 4.0 limit, and Objective-C-specific Podfile requirements.
1. Lock MapboxNavigation to a Swift 4.0-Compatible Version
Xcode 9.2 only supports up to Swift 4.0, but most recent MapboxNavigation versions require Swift 4.2+ (which needs Xcode 10+). You'll need to specify an older, compatible version in your Podfile:
# Replace the unversioned pod line with this pod 'MapboxNavigation', '~> 0.13.0'
This is the last major release that fully supports Swift 4.0 and Xcode 9.2.
2. Fix Your Podfile for Objective-C Projects
Objective-C projects need explicit configuration to work with Swift-based pods like MapboxNavigation. Make sure your Podfile includes these critical lines:
# Required sources for Mapbox and standard CocoaPods specs source 'https://github.com/CocoaPods/Specs.git' source 'https://github.com/mapbox/mapbox-cocoapods-specs.git' # Set minimum iOS version compatible with MapboxNavigation v0.13.0 platform :ios, '10.0' # Mandatory for Swift pods in Objective-C projects use_frameworks! target 'YourObjectiveCProjectName' do pod 'MapboxNavigation', '~> 0.13.0' end
Note: use_frameworks! can't be skipped—it tells CocoaPods to build Swift pods as frameworks, which Objective-C can properly import.
3. Clean and Reinstall Pods from Scratch
Old cache or corrupted Podfile.lock files often cause installation failures. Run these commands in your project directory:
# Fully remove existing pod configuration pod deintegrate pod clean rm -rf Podfile.lock # Reinstall with the fixed Podfile pod install
4. Verify Project Swift Version Settings
Even in an Objective-C project, Xcode needs to know which Swift version to use for the imported framework:
- Open your project in Xcode 9.2
- Select your project target in the Project Navigator
- Go to the Build Settings tab
- Search for "Swift Language Version"
- Set it to Swift 4.0 (matches the version MapboxNavigation v0.13.0 was built with)
5. Ensure Your CocoaPods Version is Compatible
Newer CocoaPods versions (1.6+) dropped support for older Xcode versions like 9.2. If you're running a newer CocoaPods, downgrade to a compatible version:
sudo gem install cocoapods -v 1.5.3
This is the last CocoaPods release that fully supports Xcode 9.2.
After following these steps, your pod installation should complete successfully, and you'll be able to import MapboxNavigation in your Objective-C code with @import MapboxNavigation;.
内容的提问来源于stack exchange,提问作者Niraj Paul

