未捕获的TypeError无法读取undefined的属性socialsharing

时间:2015-04-09 14:37:20

标签: javascript cordova cordova-plugins intel-xdk

我正在使用带有Cordova API的Intel XDK。我添加了社交共享插件。我已经从项目设置中将插件添加到IDE中,当我通过运行以下命令使用插件时:window.window.plugins.socialsharing.share("Hello");它在下面的Uncaught TypeError: Cannot read property 'socialsharing' of undefined下面给出了类型错误异常。我也尝试过在社交共享插件页面中给出的示例,但它们都没有为我工作。英特尔XDK已自动编写config.xml文件,以下是其中的内容

<?xml version='1.0' encoding='UTF-8'?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:intelxdk="http://xdk.intel.com/ns/v1" id="xdk.intel.blank.ad.template" version="0.0.1" android-versionCode="1">
<!--This file is generated by the Intel XDK. Do not edit this file as your edits will be lost.           -->
<!--To change the contents of this file, see the documentation on the intelxdk.config.additions.xml file.-->
<intelxdk:version value="1.0"/>
<intelxdk:cordova-cli version="4.1.2"/>
<name>My App</name>
<description>Template to develop a Cordova mobile web app using the App Designer UI editor.</description>
<author>Intel XDK</author>
<content src="index.html"/>
<intelxdk:plugin intelxdk:name="Media" intelxdk:value="org.apache.cordova.media" intelxdk:version="0.2.15"/>
<intelxdk:plugin intelxdk:name="File" intelxdk:value="org.apache.cordova.file" intelxdk:version="1.3.2"/>
<intelxdk:plugin intelxdk:name="Device" intelxdk:value="org.apache.cordova.device" intelxdk:version="0.2.13"/>
<intelxdk:plugin intelxdk:name="Social Sharing" intelxdk:value="https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin.git"/>
<intelxdk:plugin intelxdk:name="SocialSharing*" intelxdk:value="https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin"/>
<preference name="android-minSdkVersion" value="10"/>
<preference name="android-targetSdkVersion" value="19"/>
<preference name="android-installLocation" value="auto"/>
<!--creationInfo:{"src":"appDesigner","projectTypeName":"com.intel.xdk.projecttype.jsapp"}-->
<preference name="debuggable" value="false"/></widget> 

我正在使用Cordova 4.1和Intel XDK。谁能告诉我这里我做错了什么?

5 个答案:

答案 0 :(得分:0)

我一直在用这个错误撞到墙上24小时,但我终于明白了。在对github上的问题部分进行仔细研究之后,我找到了一个地方where the developer mentioned window.plugins.socialsharing将总是未定义在phonegap应用中。一旦我使用USB线运行本地构建(使用可下载的基于云的phonegap应用程序),它在第一次尝试时就能很好地工作。

另一方面,开发人员似乎非常敏感,友好且乐于助人。如果你真的陷入困境并且我的建议没有帮助,我建议仔细阅读issues section on github,看看你是否能在那里找到类似的问题。

答案 1 :(得分:0)

以下帮助了我。
删除var cordova = require('cordova'); 并添加

var cordova = window.cordova;

答案 2 :(得分:0)

我对此感到愚蠢,但我花了4个小时才弄明白我已经以某种方式删除了

    <plugin name="cordova-plugin-x-socialsharing" version="5.4.0" /> 

来自我的config.xml文件....

BTW使用build.phonegap.com构建应用程序时,使用此插件没有问题。

答案 3 :(得分:-2)

您是否在项目中包含SocialSharing.js并加载它?

<script type="text/javascript" src="js/SocialSharing.js"></script>

确保文件名中的S也是大写......

答案 4 :(得分:-2)

确保您已安装插件

cordova plugin add https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin.git