How to create Cordova iOS Phonegap Plugin (Swift)? - ios

I need to create cordova iOS phoneGap plugin using swift. I don't have any idea about this.I visited the link - "http://cordova.apache.org/docs/en/latest/guide/platforms/ios/plugin.html"
But this seems vague to me, there not step by step detailed description. Please help me out with this.(Any tutorial with step by step instructions?)
Updated
I have used tutorial - "http://moduscreate.com/writing-a-cordova-plugin-in-swift-for-ios/" and followed the same steps with the same code but got stuck while running command "cordova build ios" with the following error -
** BUILD FAILED **
The following build commands failed:
CompileXIB TestApp/Classes/MainViewController.xib
(1 failure)
Error: Error code 65 for command: xcodebuild with args: -xcconfig,/Users/kirti/testapp/platforms/ios/cordova/build-debug.xcconfig,-project,TestApp.xcodeproj,-target,TestApp,-configuration,Debug,-sdk,iphonesimulator,-destination,platform=iOS Simulator,build,CONFIGURATION_BUILD_DIR=/Users/kirti/testapp/platforms/ios/build/emulator,SHARED_PRECOMPS_DIR=/Users/kirti/testapp/platforms/ios/build/sharedpch
Please help me out.I do not understand what's the problem is?
Thanks!!

I did this plugin in order to bring the swift support in Cordova projects :
https://github.com/akofman/cordova-plugin-add-swift-support
You can have a try with it and also read the following article which is a good tutorial.

I have solved the problem finally.The reason of error "Build Failed" was due to the version of swift.In swift 3, you need to add "#objc" before function name.In my case, it's like -
#objc(echo:)func echo(command: CDVInvokedUrlCommand) {
//...enter code here
..}

Related

Swift Package Resolution Failed: artifact of binary target failed download: invalid status code 401

I am using xcode12.2 and swift 5.3. I tried the same on 12.5 and swift 5.4. But having the similar issue while trying to add my package from my github repo.
I also tried, ssh but this time it fails at first line giving fingerprint error.
pls help here, if anyone knows what's wrong here.

Kotlin Multiplatform Mobile unable to run on iOS: Execution failed for task ':shared:compileKotlinIosX64'

I have created fresh project(Hello World) in KMM followed by their official website. In android it works smooth but when I am trying to run in XCode it's giving errors because of which I am unable to build / run the xcode project. I have attached screenshots and logs for my errors. Somehow xcode scheme is not getting generated in the KMM platform that's what I am guessing.
Can anyone please help me understand what am I missing?
Any help would be appriciated.
Following is my dev env:
Xcode 11.4.1
Android 4.1.2
Kotling Plugin version 1.4.30 (stable)
KMM 0.2.0```
XCode Logs:
> Task :shared:compileKotlinIosX64
Downloading native dependencies (LLVM, sysroot etc). This is a one-time action performed only on the first run of the compiler.
Extracting dependency: /Users/fatin/.konan/cache/clang-llvm-apple-8.0.0-darwin-macos.tar.gz into /Users/fatin/.konan/dependencies
e: java.lang.RuntimeException: Cannot extract archive with dependency: /Users/fatin/.konan/cache/clang-llvm-apple-8.0.0-darwin-macos.tar.gz.
> Task :shared:compileKotlinIosX64 FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':shared:compileKotlinIosX64'.
> Compilation finished with errors
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 7s
1 actionable task: 1 executed
Command PhaseScriptExecution failed with a nonzero exit code ```
[![enter image description here][3]][3]
I reached out to community for this and finally found the solution. Here is the link to that issue which I raised and solved this problem.
If anyone else is going through this same issue it mostly cause of corrupted kotlin file.
Also try checking your cmd line tools in XCode as per comments.
Hope this helps someone. Cheers.
If the project doesn't run right away even on opening it from Xcode and shows the shared framework is missing, Then try generating the shared framework for iOS platform using terminal. Navigate to the project folder and execute
Command: ./gradlew packForXcode Now the shared framework should have a xcode-frameworks product and you should be able to build and run the project through Xcode.
This could happen if there are two libraries, where one library was compiled against the different version of the other library than the one currently used in the project. Please check that the project configuration is correct and has consistent versions of dependencies.

Issues with Xcode

I'm trying to build a simple app in Xcode however I'm getting this error saying build failed
:0: error: PCH was compiled with module cache path '/Users/apple/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/5JW54F8EE7JD', but the path is currently '/Users/Neil/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/5JW54F8EE7JD'
:0: error: missing required module 'SwiftShims'
what can I do to solve it?
You can try delete derived data of your app and then clean and build app, you can follow the steps of the following link https://programmingwithswift.com/delete-derived-data-xcode/. Also, you can follow this link Fixing Xcode

Cordova platform add ios - Error Command failed with exit code 2

I am trying to add the iOS platform to my cordova project but I keep coming across the same error. I have followed the instructions here.
When I use cordova platform add ios it gives me the following error
Shauns-MacBook-Pro:hello shaunbrown$ cordova platform add ios
Creating ios project...
Unknown option: n
Usage: head [-options] <url>...
Cordova can only run in Xcode version 4.6 or greater.
Error: /Users/shaunbrown/.cordova/lib/ios/cordova/3.5.0/bin/create: Command failed with exit code 2
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:753:16)
at Process.ChildProcess._handle.onexit (child_process.js:820:5)
I have tried looking around for the error but I can't find anything.
I am running xCode 5.1.1 so I know it doesn't have anything to do with that. Has anyone else came across this issue, or has a fix for this? I am pulling my hair out trying to fix it and so far I havent got anywhere.
I can provide more information if needed.
I managed to solve this. I opened my .bash_profile file and commented out the line that referred to my XAMPP installation.
I then restarted terminal and it worked perfectly.
You might have Xcode 5.x, but your command line tools are probably set up for a previous version.
Type:
xcodebuild -version
In a terminal. If you need to update, read this:
Xcode 4.4 and later install Command Line Tools

custom plugin installation procedure in worklight6.0

Few days back i started working on ibm worklight platformVersion="6.1.0.01.20140427-1450".
But i am facing some problem regarding custom plugin. For adding native functionality to hybrid application with apache cordova plugin in IOS I found the following link
http://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v610/06_03_iOS_-_Adding_native_functionality_to_hybrid_application_with_Apache_Cordova_plugin.pdf
I tried this but everytime on compilation i got "linker command failed with exit code 1 (use -v to see invocation)".
So my question is that after cordova 2.9 ,it stopped adding classes and files manually. So we do the same by installing the command line. But i tried the same thing in worklight based project then it gives error that it is not a cordova based project.
So i think that we can't install the plugin into worklight project with the help of command line thats why its giving the linker error.
Please try to solve my problem by proving me the solution.
Thanks in Advance
First, the error you've mentioned as-is is meaningless, you should add the full error.
Regardless,
Worklight currently does not support Cordova 3's Plugman, so you cannot easily "install" plug-ins.
As a way to show how this can be done, you can follow the guidelines provided for this question: Using katzer local notification in IBM Worklight
The solution provided in the above question shows a "step-by-step" of how to add existing Cordova 3 plug-ins to a Worklight application, for Android.
It is the same for iOS with one exception. in iOS you must reference the plug-in's .m and .h files in Xcode's Classes folder (right-click and select "Add files...")

Resources