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

Cordova插件依赖SwiftWebSocket Pod在iOS导入失败求助

Fixing 'No such module SwiftWebSocket' in Cordova iOS Swift Plugin

Hey there! I’ve run into this exact pod dependency headache when building Cordova Swift plugins before, so let’s break down how to get past that frustrating import error. Here are the key steps to check and fix:

1. Double-check your plugin.xml pod configuration

First, make sure your SwiftWebSocket framework declaration is scoped correctly to the iOS platform in plugin.xml. It’s easy to accidentally put it outside the <platform name="ios"> block, which would prevent Cordova from linking it properly. Your setup should look like this:

<platform name="ios">
    <!-- Other iOS-specific configs -->
    <framework src="SwiftWebSocket" type="podspec" spec="~> 2.6.4" />
</platform>

2. Verify Swift version compatibility

SwiftWebSocket 2.6.4 requires Swift 5.0 or later. Ensure your plugin’s target is using a compatible Swift version:

  • Open your Cordova iOS project’s .xcworkspace file (not the .xcodeproj—this is critical, since pods only work with the workspace)
  • Navigate to your plugin’s target (under the Plugins folder in Xcode’s project navigator)
  • Go to Build Settings > Swift Language Version and set it to Swift 5.0 or higher

3. Clear build caches and re-install pods

Cached build data is often the culprit here. Follow these steps to do a clean reset:

  • Close Xcode completely
  • Delete Xcode’s derived data:
    rm -rf ~/Library/Developer/Xcode/DerivedData
    
  • Navigate to your Cordova project’s ios directory and delete pod artifacts:
    rm -rf Pods Podfile.lock
    
  • Re-install pods:
    pod install
    
  • Re-open the .xcworkspace file and rebuild your project

4. Confirm SwiftWebSocket is linked to your plugin target

Sometimes Cordova doesn’t automatically link pods to plugin targets. Let’s verify:

  • In Xcode, select your plugin’s target
  • Go to Build Phases > Link Binary With Libraries
  • Check if SwiftWebSocket.framework is listed. If not, click the + button, search for SwiftWebSocket (it should be under the Pods/Products folder), and add it

5. Check your plugin’s module settings

If the above steps don’t work, make sure your plugin’s target has a valid module configuration:

  • Go to your plugin target’s Build Settings > Packaging
  • Ensure Product Module Name is a clean, non-special-character name (matching your plugin’s ID usually works)
  • Also, confirm Defines Module is set to Yes

After trying these steps, your import SwiftWebSocket statement should work without the "No such module" error. Let me know if any step needs clarification!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 07:05:20