ngCordova社交分享 - 无法阅读财产' socialsharing'未定义的

时间:2016-07-13 09:20:22

标签: cordova ionic-framework

我已安装social sharing plugin并按照说明安装ngCordova并设置config.xml文件,但是当我在Chrome浏览器中尝试使用Ionic应用程序时,我得到了错误:

  

无法阅读财产' socialsharing'未定义的

我的文件设置如下:

app.js

angular.module('myApp', ['ionic', 'ngCordova', ...other dependencies])

我的控制器中的功能:

$scope.share = function() {
    $cordovaSocialSharing.share("This is your message", "This is your subject", null, $location.absUrl());
  }

我在index.html中添加了脚本链接:

<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>

视图中共享的图标:

<img ng-click="share()" class="social-images" src="icons/facebook.svg"/>

我的config.xml的一部分:

<preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="SplashScreenDelay" value="2000"/>
  <preference name="FadeSplashScreenDuration" value="2000"/>
  <preference name="android-minSdkVersion" value="16"/>
  <preference name="BackupWebStorage" value="none"/>
  <preference name="SplashScreen" value="screen"/>
  <feature name="StatusBar">
    <param name="ios-package" value="CDVStatusBar" onload="true"/>
  </feature>
  <gap:plugin name="cordova-plugin-x-socialsharing" source="npm" />

此外,当我有这样的config.xml时,我得到一个解析错误,当我离开<gap:plugin name="cordova-plugin-x-socialsharing" source="npm" />时,它在usb插入设备上工作正常。

2 个答案:

答案 0 :(得分:1)

确保以下内容:

1-通过从CLI运行以下命令将插件添加到项目中:

  

cordova插件添加   https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin.git

2-插件列在控制器参数中:

  

app.controller(“MyCtrl”,函数($ scope,$ rootScope,...,   的 $ cordovaSocialSharing ){       ....       }

3-您正在设备模拟器中测试插件,大多数Cordova插件在浏览器中不可用。

答案 1 :(得分:0)

你已经正确地完成了它应该工作。 它在浏览器中不起作用。因此您需要使用Ionic View或您的应用才能使用和查看。所以是的:它无法在Google Chrome上运行,可能会出现错误:

public class MainActivity extends AppCompatActivity {

private RadioGroup radioGroupFirst, radioGroupSecond;
private String[] realAnswers = {"Melisa", "Android"};
private String[] userAnswers;
private TextView tv;
private boolean status = true;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    radioGroupFirst = (RadioGroup) findViewById(R.id.rg1);
    radioGroupSecond = (RadioGroup) findViewById(R.id.rg2);
    tv = (TextView) findViewById(R.id.textViewAnswer);
    userAnswers = new String[2];

    radioGroupFirst.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {

            tv.setText("");
            RadioButton nameRadio = (RadioButton) findViewById(checkedId);
            Log.e("ID", "" + nameRadio.getText().toString());
            userAnswers[0] = nameRadio.getText().toString();
        }
    });

    radioGroupSecond.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {

            RadioButton learningRadio = (RadioButton) findViewById(checkedId);
            Log.e("ID", "" + learningRadio.getText().toString());
            userAnswers[1] = learningRadio.getText().toString();
            if (checkStatus(userAnswers))
                tv.setText(getString(R.string.Good_answer));
            else
                tv.setText(getString(R.string.Wrong_answer));

        }
    });
}

private boolean checkStatus(String[] userAnswers) {
    status = true;
    for (int i = 0; i < userAnswers.length; i++) {
        Log.e(userAnswers[i], realAnswers[i]);
        if (!userAnswers[i].equals(realAnswers[i]))
            status = false;
    }
    return status;
  }
}

但这并不意味着它不适用于您的应用。因此,请先将其上传,然后在手机上试用。

这对我有用:

<强> App.js

Cannot read property 'socialsharing' of undefined

<强>控制器:

angular.module('myApp', ['ionic', 'ngCordova'])

<强>的index.html:

$scope.share = function() {
    $cordovaSocialSharing.share("This is your message", "This is your subject", null, $location.absUrl());
  }

<强> HTML:

<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>

请注意,我没有向config.xml添加任何内容。它对我来说就像这样。