我尝试创建一个Cordova/Phonegap应用程序并添加Facebook插件,但警告(typeof facebookConnectPlugin); 显示未定义:
sudo npm install -g cordova
cordova create hello com.example.hello HelloWorld
cd hello
cordova platform add ios
cordova -d plugin add https://github.com/phonegap/phonegap-facebook-plugin --variable APP_ID="1415347585409217" --variable APP_NAME="Test"
vi www/index.html # Add: alert(typeof facebookConnectPlugin); to the last <script>
cordova emulate ios
Run Code Online (Sandbox Code Playgroud)
预期:模拟器在警告对话框中显示"对象".
实际:模拟器在警告对话框中显示"未定义".
谁知道我做错了什么?
更新:感谢Devgeeks的回答如下.
以下是我需要完成的其他一些工作:
1)安装插件的较新"开发"分支:
cordova -d plugin add "https://github.com/phonegap/phonegap-facebook-plugin#develop" --variable APP_ID="1415347585409217" --variable APP_NAME="Test"
Run Code Online (Sandbox Code Playgroud)
2)在开始标记下面添加以下内容:
<!-- fb-root is needed by the FB API. -->
<div id="fb-root"></div>
Run Code Online (Sandbox Code Playgroud)
3)如果您希望FB登录在浏览器中工作(用于测试),请将www/js/facebookConnectPlugin.js复制到您的应用程序中.然后在结束标记之前包含它:
<script src="facebookConnectPlugin.js"></script>
Run Code Online (Sandbox Code Playgroud)
然后将以下内容添加到您的部分:
<script>
window.fbAsyncInit = function () {
if …Run Code Online (Sandbox Code Playgroud) jQuery.when()的文档说这个函数需要延迟。但是,它稍后还说:
如果将单个参数传递给 jQuery.when() 并且它不是 Deferred 或 Promise ...
这似乎意味着它也可以采用 Promises。但是 Promises 不是 Deferreds——它们有一个 Deferred 方法的子集。我猜你可以说 Deferred 是 Promise,但 Promise 不是 Deferred。
问题:
这个简单的代码有两个链接,"状态1"和"状态2".
当我点击"状态1"时,它会打印出"这是第一个状态".当我点击"状态2"时,它会打印出"这是第二个状态".
但是当我点击浏览器的后退按钮时,它仍然说"这是第二个状态".它不应该改为"这是第一个国家"吗?
CodePen:http://codepen.io/anon/pen/bCohi
代码:
<html>
<head>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.2.20/angular.min.js'></script>
<script type="text/javascript" src='http://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.10/angular-ui-router.js'></script>
</head>
<body ng-app="myApp">
<a ui-sref="state1">State 1</a>
<a ui-sref="state2">State 2</a>
<br>
<ui-view></ui-view>
<script>
var myApp = angular.module("myApp", ['ui.router']);
myApp.config(function($stateProvider, $urlRouterProvider) {
var stateProvider = $stateProvider;
stateProvider.state('state1', {
url: 'state-1',
template: 'This is the first state'
});
stateProvider.state('state2', {
url: 'state-2',
template: 'This is the second state'
});
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)