我已经尝试了许多不同的文件和代码组合来让这些 phonegap 构建插件发挥作用,但到目前为止没有任何效果。
这是我认为应该工作的 index.html 的开头(除了第一个脚本之外,所有脚本都不是 phonegap 插件或与 phonegap 直接相关):
<!doctype html>
<html>
<head>
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery-2.1.1.min.js"></script>
<script type="text/javascript" charset="utf-8" src="pushNotif.js"></script>
<script type="text/javascript" charset="utf-8" src="tAuth.js"></script>
<script type="text/javascript" charset="utf-8" src="printR.js"></script>
<script type="text/javascript" charset="utf-8" src="clearCache.js"></script>
这是 config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns="http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0" id="com.example.example" version="0.0.1">
<name>Example</name>
<icon src="icon.png" />
<description>
Example app.
</description>
<author email="support@example.com" href="https://example.com">
Example
</author>
<content src="index.html" />
<access origin="*" />
<preference name="phonegap-version" value="3.5.0" />
<feature name="Geolocation">
<param name="ios-package" value="CDVLocation" />
</feature>
<gap:plugin name="org.apache.cordova.inappbrowser" version="0.5.2" />
<gap:plugin name="com.oauthio.plugins.oauthio" version="0.2.4" />
<gap:plugin name="com.phonegap.plugins.pushplugin" version="2.4.0" />
<gap:plugin name="org.apache.cordova.dialogs" version="0.2.10" />
<gap:plugin name="org.apache.cordova.geolocation" version="0.3.10" />
</widget>
测试对象OAuth
(对于oauth.io)或window.plugins.pushNotification
(对于PushPlugin)是否已定义,我总是知道它们是未定义的。
在文件夹中,我将所有内容放在一起,例如:
- (基本文件)
- 配置文件
- 图标.png
- 索引.html
- (特定于应用程序的文件)
- 打印R.js
- pushNotif.js
- tAuth.js
(所有内容都在一个文件夹中,我只是将它们分开在列表中。)
所以它非常简单明了,就像我认为的说明一样。但是,不幸的是,它不起作用。
我尝试包含phonegap.js文件,包括cordova.js,包含文件cordova.js,并包含插件的js,但我认为它不是那样工作的,所以我提出的方式就是我认为应该是应该如何设置的。
这是我用来处理和检查 phonegap 插件 pushplugin 的脚本:
if(typeof window.plugins != "undefined" &&
typeof window.plugins.pushNotification != "undefined"){
alert("phonegap pushplugin plugin IS included");//this worked
handlePushNotif();
} else {
alert("phonegap pushplugin plugin not included");
}
function handlePushNotif(){
//https://github.com/phonegap-build/PushPlugin/tree/93067b9303252d5ed7394819bf220db56d99d22c
var pushNotification;
pushNotification = window.plugins.pushNotification;
//register
//Get your senderID by signing into to your google dashboard. The //senderID is found at Overview->Dashboard->Project Number.
if ( device.platform == 'android' || device.platform == 'Android' )
{
pushNotification.register(
successHandler,
errorHandler, {
"senderID":"888264849750",
"ecb":"onNotificationGCM"
});
}
else
{
pushNotification.register(
tokenHandler,
errorHandler, {
"badge":"true",
"sound":"true",
"alert":"true",
"ecb":"onNotificationAPN"
});
}
// result contains any message sent from the plugin call
function successHandler (result) {
alert('result = ' + result);
}
// result contains any error description text returned from the plugin call
function errorHandler (error) {
alert('error = ' + error);
}
//tokenHandler (iOS ony) - called when the device has registeredwith a unique device token.
function tokenHandler (result) {
// Your iOS push server needs to know the token before it can push to this device
// here is where you might want to send it the token for later use.
alert('device token = ' + result);
}
}
如果我包含PushNotification.js
脚本,我发现window.plugins.pushNotification
不是undefined
. 但是,对于 phonegap 构建,我认为它可能被设计为自动包含它。如果我不手动包含它(将文件PushNotification.js
从 git 存储库复制到项目文件并专门包含它),我会发现该对象未定义。但是,在 phonegap 构建仪表板中,它显示该插件确实包含在内。