Third party Cordova plugins undefined in P10

Third party Cordova plugins undefined in P10

  

Hello,

In our project we have to use several Cordova plugins but currently I'm having trouble with version 10.

Following the instructions in this video http://www.outsystems.com/learn/lesson/801/plugins/ I've added blank module to my application with reference to flashlight plugin and adding SwitchOn action but have an error calling it "undefined is not an object (evaluating 'window.plugins.flashlight.switchOn')"

https://cordova.apache.org/plugins/?q=flash

I've tried with another plugin that I was working with in project on platform version 9 - https://www.npmjs.com/package/cordova-plugin-zeroconf but end up with similar error "undefined is not an object (evaluating 'cordova.plugins.zeroconf.register')"


Am I missing something or there is a bug or missing steps in tutorial to access third-party Cordova plugins?


Thank you.



Hi Mykola,


Everything you did seems right, so I'm a bit puzzled. I screened the video real quick, and noticed that it doesn't refer to the actual generation of the mobile app. Did you generate and install your "PluginsTest" app, or are you testing it on OutSystems Now?

I'm not sure if you are aware, but custom plugins need to be included in the native shell. Although OutSystems Now that's available on the stores includes some plugins, new plugins need to be included in a custom version of the shell you are meant to generate.

Please find a screenshot of where to do it below.



I hope this makes it clear. This page above is clear on how and where to get what you need to generate the application, but please let me know if you have any additional question on how to do it.


Kind Regards,

João Grazina

Hi João ,

That's right - I was using OutsystemsNow app... Thank you for the hint.

However Flashlight plugin is working properly but zeroconf plugin is not..  In list of scripts I see cordova plugin file  with flashlight and other plugins installed and specific file Flashlight.js but for zeroconf none of that. I assume it is not installing correctly but can't get any clue why and how can I fix it.

I will appreciate any tip.

Thank you.

Regards,

Nick


Hi Nick,


From what I saw, you're not using the RegisterService defined in the ZeroConfPlugin eSpace, you're directly using the plugin on a JS Node in OnClickZeroconf. 

However, that should not be a problem... as long as you can check object "cordova.plugins.zeroconf" is present, the plugin should be installed, and then it's just a matter of evolving from there. Can you confirm you have that plugin present? 


Kind Regards,

João Grazina

Hi João,

That's exactly the problem - plugin seems not to be present. I've tried RegisterService on plugin eSpace and directly on JS Node but the object is undefined and looking through resources files on Safari with connected device on cordova plugins file the Zeroconf is not presented. 

However I've tried now to use only one plugin and there is an error while generating the app:
The following errors have occurred:• iOS: An unexpected error has occurred while generating your application. Please try again. If the problem persists, contact OutSystems Support.

I've attached oml files . It there any way to see what error occurs?

Hello Nick

The latest version of the plugin doesn't build in iOS. However, if you use release 1.1.2 should work.


https://github.com/becvert/cordova-plugin-zeroconf#1.1.2


Can you try it? 

Thanks

I've tried set

{
    "plugin":
    {
        "url":"https://github.com/becvert/cordova-plugin-zeroconf#1.1.2"
    }
   
}

that's correct?

and app compiled. But it crashes immediately when launching.

Hello Nick.

The problem is that they introduced a "breaking change" in the plugin in the last commit and updated the example. The example in the page uses "name" as the third parameter:

zeroconf.register('_http._tcp.', 'local.', 'Becvert\'s iPad', 80, {
    'foo' : 'bar'
}, function success(result){
    var action = result.action; // 'registered'
    var service = result.service;
});

However, in version 1.1.2 (the one I advised you) there was no name available, so, the code

let port = command.argument (at: 2) as! Int

Throws an exception because it's expecting an Integer (port) where the example is passing a string (name).

Wrapping up, the example for 1.1.2 should be something like:

zeroconf.register('_http._tcp.', 'local.', 80, {
    'foo' : 'bar'
}, function success(result){
    var action = result.action; // 'registered'
    var service = result.service;
});

With port as the third parameter.

Can you give it a try?

Thanks

That's perfect César!  Thanks a lot for the tip - it worked perfectly. I've made only one change - first parameter is domain and second is my service's name... 

zeroconf.register('http._tcp.local.', 'test service name', 80, {...});

That will work for now:) I'm very glad and thank you very much.



Hi César,

I have again same problem but on another environment now...

It is not working on our Development environment (no latest version not previous that worked on personal environment)
I've tried
{
    "plugin":
    {
        "url":"https://github.com/becvert/cordova-plugin-zeroconf"
    }
}

and 
I've tried
{
    "plugin":
    {
        "url":"https://github.com/becvert/cordova-plugin-zeroconf#1.1.2"
    }
}


Environment Version 10.0.105.0

Are there more details from the error and how to resolve this issue?


Thank you

Hello Nick.

What's the behavior you're getting? Do you have an error when building the application or the plugin isn't there?

Thanks

Hello César,

Thanks for quick reaction :)

I can't build iOS native app:

The following errors have occurred:
• iOS: An unexpected error has occurred while installing the Cordova plugins. Please try again. If the problem persists, contact OutSystems Support.


Android is building and working on both versions.

Hello Nick.

Sorry for the late reply. Can you retry and see if it builds? 

Thanks

Hi César,

It is still same error. Also I've tried to compile again on personal environment and it is not working now showing same error message... That is weird... Are there constant changes on the script that generates apps or it is tied to platform version? 

Might it be related that versions of Platform are different - on my personal its 10.0.200.2 and on dev  is 10.0.105.0?




Solution

Hello Nick.

Can you try the latest version? #1.2.1?

Thanks

Solution

Hi César,

It did work. 

Thank you very much.