9

I'm working on an Ionic React Project running on top of Capacitor. I added Android platform and everything went smoothly. Now that I'm trying to make my app work in iOS (first time working with iOS), after adding ios platform and open my project in XCode, I ran into some issues.

See the errors:

enter image description here

enter image description here

Podfile content:

enter image description here

Any help would be really appreciated. Thank you!

Ani
  • 788
  • 3
  • 7
  • 21

7 Answers7

12

For anyone interested, I deleted ios folder and added iOS platform again. After that, instead of running 'pod install' (I got errors via this command), I used these commands:

in regular terminal, outside the Project directory:

sudo arch -x86_64 gem install ffi

then inside iOS folder

arch -x86_64 pod install

After these commands, all capacitor pods/plugins got installed successfully. I opened the app using this command: ionic cap open ios and got an error: No module Capacitor found, but anyway I ignored this error and ran/build the app inside XCode. The emulator got opened successfully and the app ran smoothly.

Ani
  • 788
  • 3
  • 7
  • 21
12

In my case I was opening .xcodeproj instead of xcworkspace in xcode. Once I opened the . xcworkspace file, app built successfully.

Difference between the two is explained well here: https://stackoverflow.com/a/21631534/4868839

User3250
  • 2,961
  • 5
  • 29
  • 61
6

I faced the same problem today. After doing some research I finally made my project work on iOS! I am using Angular version 9. I could not run the XCode project since ionic would not create the required podfile. I simply created the iOS app with npx first and then used ionic to run a live reload of my app. The commands are the following:

  1. npm install @capacitor/ios
  2. npx cap add ios
  3. ng build (creates the www directory)
  4. npx cap open ios
  5. ionic capacitor run ios --livereload --external
  6. Run the app from XCode in order to get the app's logs during runtime

(Sources: npx and ionic)

5

The problem with editing your Podfile directly within the iOS bundle in Xcode is that every time you build your bundle, you risk losing the changes you have made to the Podfile.

Capacitor should build it for you automatically when you run ionic cap add ios or ionic cap build ios.

If it doesn't, you could try deleting the iOS bundle in your IDE (e.g. VS Code) and then add it again using the CLI.

Obviously a Podfile will differ from project to project, but one generated with Ionic/Capacitor generally looks like this:

platform :ios, '12.0'
use_frameworks!

# workaround to avoid Xcode caching of Pods that requires
# Product -> Clean Build Folder after new Cordova plugins installed
# Requires CocoaPods 1.6 or newer
install! 'cocoapods', :disable_input_output_paths => true

def capacitor_pods
  pod 'Capacitor', :path => '../../node_modules/@capacitor/ios'
  pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios'
  pod 'CapacitorApp', :path => '../../node_modules/@capacitor/app'
  pod 'CapacitorDevice', :path => '../../node_modules/@capacitor/device'
  pod 'CapacitorGeolocation', :path => '../../node_modules/@capacitor/geolocation'
  pod 'CapacitorHaptics', :path => '../../node_modules/@capacitor/haptics'
  pod 'CapacitorKeyboard', :path => '../../node_modules/@capacitor/keyboard'
  pod 'CapacitorLocalNotifications', :path => '../../node_modules/@capacitor/local-notifications'
  pod 'CapacitorNetwork', :path => '../../node_modules/@capacitor/network'
  pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar'
  pod 'CapacitorStorage', :path => '../../node_modules/@capacitor/storage'
  pod 'CordovaPlugins', :path => '../capacitor-cordova-ios-plugins'
end

target 'App' do
  capacitor_pods
  # Add your Pods here
end
Super_Simon
  • 1,250
  • 8
  • 25
  • 1
    I deleted ios folder and ran again: ionic cap add ios. Now, Podfile contains Capacitor inside but the problem is that No Podfile is in project structure when I open my project in XCode. – Ani Jul 07 '21 at 11:01
  • 1
    Have you tried running `ionic cap build ios`? – Super_Simon Jul 07 '21 at 11:07
  • 2
    Yes and it fails! an error occurred while running Capacitor, capacitor sync ios exited with code -1. there are too many logs but one of them was: Pod install failed and Bus Error – Ani Jul 07 '21 at 12:44
1

If capacitor is a Pod I am assuming it since you have attached your podfile,

Then add Capacitor pod with version to the podfile And run pod install It should be available,

Otherwise if it a external framework make sure to add it to the project and copy it under Target-> BuildPhases-> Link Binary With Libraries Option

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 1
    Like this: pod 'Capacitor' ? Is this enough? – Ani Jul 07 '21 at 09:44
  • 1
    I added it like this: target 'App' do pod 'Capacitor', '~> 3.0.0' end and ran pod install, but the error is still there. Should I do any clean or sth? – Ani Jul 07 '21 at 09:53
  • 1
    it should be like `target 'App' do pod 'Capacitor'` or if you have a version `pod 'Capacitor', '3.0.0'` – nitin upadhyay Jul 07 '21 at 10:19
1

I already had an IOS folder generated, so I deleted it and ran the following commands:

  1. npx cap add ios

  2. ionic build ios or ng build

  3. npx cap sync ios only if is necessary

  4. npx cap open ios

James Risner
  • 5,451
  • 11
  • 25
  • 47
0

If you're trying to use multiple schemes within your capacitor project, I resolved this by adding this to my project's Podfile:

target 'TARGETNAME' do
  capacitor_pods
  # Add your Pods here
end

It's in the docs here

Sam Borick
  • 935
  • 2
  • 10
  • 31