Swift Cordova bridge undefined error - ios

I'm following instructions at http://moduscreate.com/writing-a-cordova-plugin-in-swift-for-ios/ to generate a Swift based Cordova plugin for IOS.
When I get as far as adding the IOS platform via command 'cordova platform add ios' I'm expecting something like the example:
Adding ios project...
iOS project created with cordova-ios#4.0.1
Discovered plugin "cordova-plugin-whitelist" in config.xml. Installing to the project
Fetching plugin "cordova-plugin-whitelist#1" via npm
Installing "cordova-plugin-whitelist" for ios
Installing "cordova-plugin-add-swift-support" for ios
Update IOS build setting SWIFT_OBJC_BRIDGING_HEADER to:
/Users/simon/projects/modus/swiftplugin/modusechopluginswift/testapp2/platforms/ios/TestApp/Bridging-Header.h
Update IOS build setting EMBEDDED_CONTENT_CONTAINS_SWIFT to: YES
What I actually get is:
Adding ios project...
Creating Cordova project for the iOS platform:
Path: platforms/ios
Package: com.moduscreate.testapp
Name: TestApp
iOS project created with cordova-ios#4.2.1
Installing "cordova-plugin-add-swift-support" for ios
Error: undefined is not a function
The platforms folder has a generated IOS subfolder with content.
I assume the problem is with the cordova-plugin-add-swift-support plugin.
I'm running xCode 8.0 on macOS Sierra 10.12.
Does anybody have any ideas?

I'm the author of the tutorial you were following. I recently updated it to address changes for Swift 3, so if you want to try this with the latest Cordova, XCode 8.2 and Swift 3 syntax, I've produced a new tutorial here. Following this may solve your issues.

Related

Unable to find command: platform add ios

I have a old ionic project that run in version 1.3.3. And I updated to new version 5.4.16. But, when I try build the project using "ionic platform add ios"
Its doesn't work and I receive this message:
Unable to find command: platform add ios
I look for this in doc, but nothing done.
Is there anything I can do or some other command that replaces ionic platform add ios in newer versions?
It's: ionic cordova platform add ios
https://ionicframework.com/docs/cli/commands/cordova-platform

ionic 4 ios fails to build due to swift version 3

After upgrading to xcode 10.2 my ionic for ios project stopped building using below command
ionic cordova build ios -- --buildFlag="-UseModernBuildSystem=0"
i tried to upgrade cordova-ios#5.0.0 and remove and readd ios platform but no luck.
The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift. Supported values are: 4.0, 4.2, 5.0. This setting can be set in the build settings editor.
Code Signing Error: Code signing is required for product type 'Application' in SDK 'iOS 12.2'
** ARCHIVE FAILED **
The following build commands failed:
Check dependencies
(1 failure)
xcodebuild: Command failed with exit code 65
[ERROR] An error occurred while running subprocess cordova.
cordova build ios --buildFlag=-UseModernBuildSystem=0 exited with exit code 65.
Re-running this command with the --verbose flag may provide more information.
I ran into the same error. I first tried to switch the Swift Language version in the Xcode build setting and quickly realized that some plugins written in Swift broke. Thankfully the plugin which broke for me was QR Scanner which is well maintained and has been updated for Swift 5.
So what I did to fix it was first run the following node commands to find and update the outdated node packages.
npm outdated
npm update
Then I identified the outdated/broken cordova plugins, removed them, then reinstalled the latest versions. Using
cordova plugin list
to make sure everything was updating correctly, cross referencing with the version numbers with the plugins repo. Then finally I added this to the config.xml
<preference name="UseSwiftLanguageVersion" value="5" />
and everything built successfully when running,
ionic cordova build ios -- --buildFlag="-UseModernBuildSystem=0"
Unfortunately, if you're using a cordova plugin that is written in Swift and is not well maintained you're out of luck. You can try to update the plugin yourself if you're brave.
Hopefully this was helpful and doesn't require you to role back your Xcode, losing the ability to build for the latest version of iOs.
You should go with below steps-
Open your project in Xcode by click on workspace file in platforms >> ios >> PROJECT_NAME.xcworkspace
Go for Build Settings
Now search "Swift Language Version"
Change the version to 4 or 5(whichever required)
run below command
Ionic cordova build ios --buildFlag="-UseModernBuildSystem=0"
Just add this plugin
cordova plugin add cordova-plugin-add-swift-support --save
Or if you already added then just remove this plugin and add again.

Cordova build IOS with CocoaPods configured

I have created a Cordova project using my mac and I added IOS platform tot he project (cordova platform add ios)
On adding plugins, phonegap-plugin-push plugin expects to use CocoaPods to manage tthe plugin. After adding the plugin and adding the Platfom, I build the project using the command cordova build ios
It looks like it is trying to build the CocoaPods project created when adding the platform and it is getting failed. Below is the error. It should build my Xcode project.
Error: /Library/Ruby/Gems/2.0.0/gems/claide-1.0.1/lib/claide/command.rb:439:in `help!': [!] You cannot run CocoaPods as root. (CLAide::Help)
Can anyone help me to build my IOS project.
My Cordova version is 6.4.0; My IOS version is 10.11.6; My Xcode version is 8.1
Thanks.

Cordova 5 not handling new ios application target in XCode

I just upgraded to Cordova 5. Any XCode project that has more than one application target causes an error on build.
cordova build ios
could not find -Info.plist file, or config.xml file.
Steps to recreate:
Create a new Cordova project
Add iOS as a platform
In the XCode project, duplicate the application target to create a new target
Run "cordova build ios"
Currently using XCode 6.3.2 and Cordova 5.1.1
There is a pull request with a fix: https://github.com/apache/cordova-lib/pull/219
Until Cordova team fix it, look here:
Second answer

PhoneGap CLI "cordova build ios" failed

i have created a new hello world project using the following command,
cordova create hello com.example.hello HelloWorld
the project is created successfully, then i add the ios platform by
cordova platform add ios
and to verify i have it added correctly, i type
cordova platform list
the iOS platform is shown in the list. so at this point, according to the PhoneGap tutorial, i can use the command
cordova build ios
to build the iOS version of the project. however, i encounter the following error:
Generating config.xml from defaults for platform "ios"
Preparing ios project
Compiling app on platform "ios" via command "/Users/Aldour/PhoneGap/hello/platforms/ios/cordova/build"
/usr/local/lib/node_modules/cordova/node_modules/q/q.js:126
throw e;
^
Error: An error occurred while building the ios project.
at ChildProcess.<anonymous> (/usr/local/lib/node_modules/cordova/src/compile.js:65:22)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:735:16)
at Socket.<anonymous> (child_process.js:948:11)
at Socket.EventEmitter.emit (events.js:95:17)
at Pipe.close (net.js:466:12)
the results that i have googled are mostly concerning the android version, talking about the invalid environment path setting. i dont know if it is related since i can create and build a PhoneGap project targeting the android platform without problem.
here is my $PATH:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/bin/node:/usr/local/bin/npm:/Developer/SDKs/android-sdk-macosx/platform-tools:/Developer/SDKs/android-sdk-macosx/tools
EDIT:
problem solved by re-installing xcode from app store
I had the same problem in Android platform, and it was solved with the commands:
cordova platform rm android
cordova platform add android
cordova build android
in Node.Js console. try it in ios.
If you get an error with 'cordova platform add android', you may need to manually remove any android folders in your project folder hierarchy.
This resolved my issue:
cordova platform remove ios
cordova platform add ios
cordova build ios
If you run the build with --verbose, you will probably see some permission issues. By default, XCode creates a folder of the build in ~/Developer, if you haven't changed it. There probably is a permissions issue when creating that folder. Just execute the following command: sudo cordova bulid ios
That should fix your issue.

Resources