Javascript Phonegap构建插件不包括在内
为了让这些phonegap构建插件正常工作,我尝试了许多不同的文件和代码组合,但到目前为止没有任何效果 这是index.html的开始,我认为应该可以使用(除了第一个脚本之外,所有脚本都不是phonegap插件或与phonegap直接相关):Javascript Phonegap构建插件不包括在内,javascript,cordova,phonegap-pushplugin,Javascript,Cordova,Phonegap Pushplugin,为了让这些phonegap构建插件正常工作,我尝试了许多不同的文件和代码组合,但到目前为止没有任何效果 这是index.html的开始,我认为应该可以使用(除了第一个脚本之外,所有脚本都不是phonegap插件或与phonegap直接相关): 如果我包括PushNotification.js脚本,我会看到window.plugins.PushNotification不是未定义的。然而,使用phonegap构建,我认为它可能被设计为自动包含它。如果我不手动包含它(将文件PushNotificati
如果我包括
PushNotification.js
脚本,我会看到window.plugins.PushNotification
不是未定义的。然而,使用phonegap构建,我认为它可能被设计为自动包含它。如果我不手动包含它(将文件PushNotification.js
从git存储库复制到项目文件,并专门包含它),我会发现该对象没有定义。但是,在phonegap构建仪表板中,它向我显示插件确实包含在内。您的config.xml无效。这些线路很糟糕:
<!doctype html>
<html>
<head>
很抱歉,这是我问题中的一个错误。这个问题看起来像是我忘了把这些行放在index.html
代码的顶部,所以我复制了它们并随意地粘贴到config.xml
代码中。事实上,我只是没有在前面留下足够的空间,所以这些行没有出现。现在问题已经解决了。在您的项目中,当您单击“插件”选项卡时,是否列出了任何内容?所有插件都已正确列出。我发现其中一些被包括在内。特别是有一个,com.oauthio.plugins.oauthio
不能正常工作。不确定该怎么处理这个问题,因为从技术上讲,现在可能是一个不同的问题——一个关于特定插件的问题。实际上,最初的问题仍然适用。推送通知插件PushPlugin
的运行方式与我预期的完全不同。我使用的脚本基于文档脚本。我已将其添加到问题中。我检查了设备
对象,即未定义
。我必须包含PushNotification.js
,以便对象窗口.plugins.PushNotification
不被定义,尽管我认为可能phonegap build将脚本作为插件过程的一部分注入页面。@Ajoy我从来没有这样做过。我现在正在本地使用cordova。
<?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>
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);
}
}
<!doctype html>
<html>
<head>