Problems creating a NativeScript plugin that uses Objective-C code - objective-c

I have followed the NativeScript documentation on adding Objective-C code to a NS project although I am struggling to call the Objective-C code in my iOS project. I am only trying to implement appPlugin.h and appPlugin.m files into my project.
My folder structure for the Objective-C files are as follows:
Project/app/App_Resources/iOS/src/...
I have also tried creating a NativeScript plugin that gets added to the dependencies in the projects package.json.
Are there any additional files that need to be added to make the Objective-C code compatible with the NS project. The documentation simply says run "If you run 'tns prepare ios' you will see that the files are now part of the project."
Link to the documentation I have been following:
https://www.nativescript.org/blog/adding-objective-c-code-to-a-nativescript-app
https://docs.nativescript.org/plugins/building-plugins

SOLVED: Files are added to the TNSNativeSource folder (Check in Xcode) and are available to use like any JS object.

Related

How to include objectiveC dependency in a swift library

Xcode cannot find references to a obj-c library after adding the dependency to my library's Podspec file
I'm trying to write a flutter iOS plugin for the GVRAudioEngine. There are two parts to this:
The plugin implementation, which instantiates a native object--in this case a GVRAudioEngine instance--and a communication channel to the dart world. Dependencies for this part are defined in a Podspec file
A sample app that runs the plugin--for debugging and documentation purposes. Here is where a sample AppDelegate class would get implemented. Dependencies for this part are defined in a Podfile
I've been able to include the GVRAudioEngine as a Podfile dependency accessible from the sample app. For this I've had to create a header bridge.
However,I've so far not been able to access GVRAudioEngine from the library side i.e Podspec. I've added the dependecies, and tried creating a header bridge there, or checking the framework and header paths. I've not been able to get this to work.
Comparing this library to other libraries I do have access to, the only differences I've found so far are:
This one is written in objc
the framework is a .a file
I'm close to giving up. I'm a new iOS developer, so I fear there's something super obvious I'm missing.
I've added the following lines to my Podspec file.
s.dependency 'GVRKit', '1.140.0'
s.dependency 'GVRAudioSDK', '1.140.0'
s.static_framework = true
I expect to be able to declare a field of type GVRAudioEngine in my Podspec library. But Xcode complains that the type is undeclared

Calling *.aar files (android library) in nativescript vue

I already create an .aar (android library) files in android studio and want to call/use it in nativescript-vue project.
I have placed the aar file in "app/App_Resources/Android/libs" folder.
Based on my reading, in typescript the way to call the method in aar files is by calling com.package.MyClass.
My question is , how to call it in .vue files. I have tried to call the method using the same approach but its produce an error :
Module not found: Error: Can't resolve com.package.MyClass
Can someone please help me on this.
Your help is very much appreciated.
You may simply place your AAR file in your App_Resources/Android/libs directory, CLI will pick it up at build time and the native APIs should be available at runtime within your project.
Try a clean build if you see errors, make sure the AAR is picked up. You might be able to verify it from the CLI logs. If you still see issues, make sure the class you are trying to access is public.
I'm not sure it's possible to use the android lib directly in the main project or not. In my way, I create a NS plugin that includes the .aar library, then add this plugin to the main project & use the methods defined in the .aar library without problem.
If you place the .aar library in the main project, you should check if that .aar library is installed by running tns build command & look at console log. If it's installed together with the project, that means you can use the lib method in .vue or any .js files.

Compilation issues with Mix and Match Objective-C & Swift Cocoapod

I'm working on a large mixed Objective-C and Swift codebase. I'm trying to move some of the code into a separate framework. This is going to end up being imported into the main project via a Cocoapod. The separate framework will end up having both Objective-C and Swift code.
So far I've moved all of the files for the new separate framework out of the main project and into a new folder. I've referenced these new files via a podspec and I'm importing them back into the main project as a development pod. All I'm trying to do right now is get this new framework to build on its own, I'm not trying to build it as part of the entire project yet.
The part I'm currently stuck on is, when it builds, in the MySplitOutFramework-Swift.h that it generates there is a a compilation error. The compilation error is on the line #import <MySplitOutFramework/MySplitOutFramework.h>. The error say 'this file cannot be found'.
What exactly am I doing wrong here? Is it some kind of circular dependency?

Xcode 4 adding dylib

I am trying to create and then add the dylib to a project.
I created it by using the "Cocoa-Library" template and setting the type to "Dynamic" (not sure if it should be dynamic or static...). Then I created a simple obj-c class called Test and wrote a method in it that prints out something to console.
I compiled and used the generated .dylib file and put it in another project. Now whenever I try to use it, I get this message on runtime"
dyld: Library not loaded: /usr/local/lib/TESTLib.dylib
Referenced from: /Users/***/Library/Developer/Xcode/DerivedData/TestingDYLIB-axmoocnxbwznoyerfogosumqufxc/Build/Products/Debug/TestingDYLIB.app/Contents/MacOS/TestingDYLIB
Reason: image not found
I also created a Copy File phase and set the destination to "Frameworks". I still get the same error.
What am I doing wrong?
The issue is not where Xcode is looking for the library at compile time, which is what Simon Whitaker's answer addresses.
The issue is that the application which uses the dylib cannot find it at runtime. When an application is built that uses a dynamic library, it copies the install_name of the dylib into the output binary.
Creating a copy files phase and copying the dylib to the Frameworks subdirectory of the app's bundle is the right thing do do.
However, you need to do an additional step. You need to compile the dynamic library with an install_name appropriate for a bundle app. By default, a dynamic library is created with an install_name of /usr/local/lib. The app can't find your library there because it doesn't exist. Even if you put the library there, your users certainly won't have it, so that would be the wrong solution.
The right solution is bundling the library with the app. To set the install name for the dynamic library, go into the dynamic library project and set the "Dynamic Library Install Name" option to: #executable_path/../Frameworks/libmydynamiclibrary.dylib
Xcode is looking in /usr/local/lib/ for the library. If the library is in another location, add that location to your Library Search Paths:
Select project file in Xcode 4
Select the target, then click the Build Settings tab
Make sure All is selected in the filter bar (not Basic)
Scroll down to the Search Paths section and you'll find Library Search Paths in there

How can I work with code completion in Xcode 4?

How can I work with code completion in Xcode 4 when I create a new project using a Template and have a static library.
I created a new template that uses static library but when I create a new project the code completion doesn't work for static library. I can build and run the new project well and use code completion for the clases inside the project.
Thanking you in advance.
This could be caused by a known bug with Xcode's code completion. Any files that lie outside the project's root directory will not be indexed properly which means code completion and refactoring operations for any symbols defined in those files will not work.
I have filed a bug for this previously and it has been confirmed by Apple (original bug ID: 9260761).
The work around is to make sure the header files lie inside your project directory somewhere and that they have been added to your Xcode project.
You should add static library headers to your project as well. That's how Xcode knows what classes/methods to autocomplete.