[ 
https://issues.apache.org/jira/browse/CB-10599?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Konstantin Preißer closed CB-10599.
-----------------------------------
    Resolution: Fixed

> Plugin JS objects are undefined when running on iOS with Cordova >= 5.4.0 
> (e.g. 6.0.0)
> --------------------------------------------------------------------------------------
>
>                 Key: CB-10599
>                 URL: https://issues.apache.org/jira/browse/CB-10599
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: iOS
>         Environment: Windows 10 x64, Visual Studio 2015 Update 1 with Tools 
> for Apache Cordova Update 6
>            Reporter: Konstantin Preißer
>              Labels: plugin
>
> Hi,
> I originally reported this issue here: 
> https://github.com/phonegap/phonegap-plugin-push/issues/605 but found it does 
> not apply to that plugin only, but to all plugins.
> I'm using Visual Studio 2015 (Update 1) with Tools for Apache Cordova Update 
> 6 on Windows 10 x64. When I create a Cordova project and use a Cordova CLI 
> version > 5.3.3 (e.g. 6.0.0, 5.4.1 or 5.4.0) and add plugins to it, then 
> JavaScript variables defined by those plugins (e.g. PushNotification) are 
> undefined in the deviceReady event, at least when running on iOS 9.2.1. With 
> Cordova 5.3.3 however, everything works.
> I used these steps to reproduce:
> 1) In Visual Studio 2015 with Cordova Tools Update 6, I created a new Cordova 
> project.
> 2) Double-clicked on config.xml, then on the Platforms tab I selected "6.0.0" 
> for Cordova CLI version.
> 3) On the Plugins tab, I added the phonegap-plugin-push plugin using the Git 
> URL (Version 1.5.3): https://github.com/phonegap/phonegap-plugin-push
> 4) On the Common tab (the first tab), I entered "index.xhtml" as start page.
> 4) In the projects www folder, I removed the default files, and then placed 
> the following index.xhtml file (the extension ".xhtml" is importand so that 
> the document is treated as XML instead of HTML, which is what I'm using):
> {code:xml}
> <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE html>
> <html xmlns="http://www.w3.org/1999/xhtml";>
> <head>
>     <title>Test Push on iOS</title>
>     <!-- Cordova-Script -->
>     <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
>     <script type="text/javascript" charset="utf-8" 
> src="scripts/platformOverrides.js"></script>
>     <script type="text/javascript" charset="utf-8" src="myscript.js"></script>
> </head>
> <body>
>     <div>Test</div>
>     <pre id="result"></pre>
> </body>
> </html>
> {code}
> Then added the following myscript.js:
> {code:javascript}
> (function () {
>     // Listen for the device ready event.
>     document.addEventListener('deviceready', handleDeviceReady.bind(this), 
> false);
>     function logConsole(text) {
>         
> document.getElementById("result").appendChild(document.createTextNode(text + 
> "\r\n"));
>     }
>     function handleDeviceReady() {
>         logConsole("DeviceReady. Trying to register...");
>         try {
>             // Register for notifications.
>             var push = PushNotification.init({
>                 android: {
>                     senderID: "123456",
>                     clearNotifications: false
>                 },
>                 ios: { alert: true, sound: true },
>                 windows: {}
>             });
>             logConsole("Register called.");
>             push.on('registration', function (data) {
>                 logConsole("Registration received: " + data.registrationId);
>             });
>         } catch (e) {
>             logConsole("EXCEPTION: " + e);
>         }
>     }
> })();
> {code}
> 5) Then I built the project for iOS using the instructions at 
> http://taco.visualstudio.com/en-us/docs/run-app-ios/#iOSDevice (in VS 
> toolbar, I selected "Debug", "iOS", "Local Device") and then created the 
> project).
> 6) When running the app on a iPad with iOS 9.2.1, the document shows 
> "ReferenceError: Can't find variable: PushNotification".
> 7) Then I opened the config.xml again, and set the Cordova CLI version to 
> "5.3.3". To ensure everything is built again, I deleted the "bin", "bld" and 
> "platform" folders in the project directory. (Or better: Create a completely 
> new project.)
> 8) After building and running the app again, it works correctly, showing 
> "Registration received" with the registration ID.
> Note, that with Cordova CLI 5.4.1 and 5.4.0, the same error (ReferenceError) 
> happens as with 6.0.0. However I want to upgrade to Cordova 6.0.0 so that I 
> can use the newer WKWebView.
> Note that this also applies e.g. when using cordova-plugin-globalization: 
> navigator.globalization is undefined with Cordova 5.4.0-6.0.0 on iOS but 
> works with 5.3.3.
> Note: When building for Windows 10 (in the config.xml with the Windows Tab, 
> select Target version "Windows 10.0", then in the VS toolbar selecting Debug, 
> Windows-AnyCPU, Local Computer) and running the app locally, there seems to 
> be a similar problem with Cordova 6.0.0: On the first run, the plugin 
> variables are undefined just like on iOS, but on the second run, it works. 
> With Cordova 5.3.3 it works even at the first run.
> Thank you!



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to