Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling native methods in NativeScript with multiple arguments #2653

Closed
mdanishs opened this issue Aug 31, 2016 · 4 comments
Closed

Calling native methods in NativeScript with multiple arguments #2653

mdanishs opened this issue Aug 31, 2016 · 4 comments

Comments

@mdanishs
Copy link

I am trying to implement a plugin in NativeScript which uses a pod and pod has the following methods.

// basic usage
[self.view makeToast:@"This is a piece of toast."];

// toast with a specific duration and position
[self.view makeToast:@"This is a piece of toast with a specific duration and position." 
            duration:3.0
            position:CSToastPositionTop];

the basic usage works fine like this:
frameModule.topmost().ios.controller.view.makeToast("sometext");

but when i try to send multiple parameters for specific duration and position

frameModule.topmost().ios.controller.view.makeToast(toastObject.text, 5.0, CSToastPositionTop);

I get this exception in console

Actual arguments count: "3". Expected: "1".

How do we send multiple parameters in to call native functions?

@m-abs
Copy link
Contributor

m-abs commented Aug 31, 2016

It has to do with the way {N} maps to native function in Objective-c:

I think this is what you need:
https://docs.nativescript.org/runtimes/ios/marshalling/Marshalling-Overview.html#objective-c-selectors

It might help you to generate typescript type definitions for your module

TNS_TYPESCRIPT_DECLARATIONS_PATH="${pwd}/typings" tns build ios

from: https://docs.nativescript.org/runtimes/ios/how-to/Use-Native-Libraries

@mdanishs
Copy link
Author

mdanishs commented Aug 31, 2016

@m-abs i went through the links, I get marshalling a bit, but it is for data types, and the second link doesn't give examples, I am using the cocoapods technique. My pods are working fine and methods with only one argument are working fine as well. What I am not getting is to call native methods with more than one argument, any example would help

@mdanishs
Copy link
Author

@m-abs just tried TNS_TYPESCRIPT_DECLARATIONS_PATH="${pwd}/typings" tns build ios to see the exposed API I get it now. Thanks a lot.

@lock
Copy link

lock bot commented Aug 29, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Aug 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants