Search code examples
iosxcodecocoapodscapacitorcapacitor-plugin

How to integrate a pod library in an iOS Capacitor Plugin?


I want to use an external library named SwiftSocket in my own iOS Capacitor plugin:

enter image description here

In the Podfile, I have:

require_relative '../../node_modules/@capacitor/ios/scripts/pods_helpers'
platform :ios, '13.0'
use_frameworks!
install! 'cocoapods', :disable_input_output_paths => true

def capacitor_pods
  pod 'Capacitor', :path => '../../node_modules/@capacitor/ios'
...
  pod 'CapacitorGoodipClient', :path => '../../../client-capacitor'
end

target 'App' do
  capacitor_pods
  pod 'SwiftSocket', :git => 'https://github.com/swiftsocket/SwiftSocket.git', :branch => 'master'
end

post_install do |installer|
  assertDeploymentTarget(installer)
end

When I compile, I receive the error "No such module 'SwiftSocket'". What am I doing wrong? I have done "ionic cap sync ios", "pod deintegrate", "pod install", "pod update".

My question could be formulated in a more generic way: What is the process to integrate a third-party library in a Capacitor plugin for the iOS platform?


Solution

  • There are two files involved, the Podfile and the .podspec file. This second file includes "dependency" which is not part of the Podfile.

    The solution consists in adding

    s.dependency 'SwiftSocket'
    

    in the .podspec file (not in the podfile). More explanations here.