我已经尝试了许多不同的文件和代码组合来使这些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)是否已定义,我总是认为它们未定义。
在文件夹中,我将所有内容放在一起,例如:
(一切都在一个文件夹中,我只是在列表中将它们分开。)
所以它非常简单明了,就像我认为指示一样。但是,遗憾的是,它无法正常工作。
我尝试包含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构建仪表板中,它向我显示插件确实包含在内。
答案 0 :(得分:1)
您的config.xml无效。这些线路很糟糕:
<!doctype html>
<html>
<head>