我尝试了许多不同的文件和代码组合,以使这些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)是否已定义,我总是发现它们是未定义的。
在文件夹中,我把所有东西都放在一起,比如:
- (基本文件)
- config.xml
- icon.png
- index.html
- (应用程序特定文件)
- printR.js
- pushNotif.js
- t作者.js
(所有东西都在一个文件夹中,我只是把它们放在列表中。)
因此,它非常简单明了,正如我所认为的说明所包含的那样。然而,不幸的是,它不起作用。
我试着包含phonegap.js文件,包括cordova.js,包含文件cordovajs,并包含插件的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构建面板中,它向我展示了插件确实包含在内。
您的config.xml无效。这些线路很糟糕:
<!doctype html>
<html>
<head>