Ios phonegap构建通用推送插件-无有效的aps环境
我正在尝试对我的应用程序使用通用推送。它可以在android上工作,但在ios上我得到错误消息:没有有效的aps环境Ios phonegap构建通用推送插件-无有效的aps环境,ios,cordova,push-notification,Ios,Cordova,Push Notification,我正在尝试对我的应用程序使用通用推送。它可以在android上工作,但在ios上我得到错误消息:没有有效的aps环境 我在apple provisioning中添加了推送通知的支持 侧面图 启用推送后,我创建并下载了配置文件 我在mobileprovision中有aps环境 我已在手机上安装了移动设备和应用程序 我检查并测试了每种解决方案 my config.xml <?xml version="1.0" encoding="UTF-8" ?> <wid
aps环境
<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "---.-------.-----"
versionCode="10"
version = "1.1.0">
<!-- versionCode is optional and Android only -->
<name>PhoneGap push Example</name>
<description>
An example for phonegap build docs.
</description>
<author href="http://-----------" email="---------------">------</author>
<access origin="*" />
<!--DEVICE FEATURES ACCESS-->
<feature name="http://api.phonegap.com/1.0/camera"/>
<feature name="http://api.phonegap.com/1.0/file"/>
<feature name="http://api.phonegap.com/1.0/geolocation"/>
<feature name="http://api.phonegap.com/1.0/media"/>
<feature name="http://api.phonegap.com/1.0/network"/>
<feature name="http://api.phonegap.com/1.0/notification"/>
<gap:plugin name="GenericPush" /> <!-- latest release -->
</widget>
PhoneGap推送示例
phonegap构建文档的示例。
------
我的js
通知;
函数ondevicerady(){
$(“#应用程序状态ul”).append(“收到设备日常事件” ”);
pushNotification=window.plugins.pushNotification;
if(device.platform==“android”| | device.platform==“android”){
register(successHandler,errorHandler,{“senderID”:“661780372179”,“ecb”:“onNotificationGCM”});
}否则{
寄存器(tokenHandler,errorHandler,{“badge”:“true”,“sound”:“true”,“alert”:“true”,“ecb”:“onNotificationAPN”});
}
}
//处理iOS的APNS通知
函数onNotificationAPN(事件){
if(event.alert){
$(“#应用程序状态ul”).append(“推送通知:”+event.alert+“ ”);
navigator.notification.alert(event.alert);
}
if(事件声音){
var snd=新媒体(事件声音);
snd.play();
}
if(事件徽章){
pushNotification.setApplicationBadgeNumber(successHandler,event.badge);
}
}
//处理Android的GCM通知
通知GCM(e)的功能{
$(“#应用程序状态ul”).append(“事件->接收:“+e.EVENT+” ”);
开关(如事件)
{
“已登记”案件:
如果(e.regid.length>0)
{
$(“#应用程序状态ul”)。附加(“已注册->REGID:”+e.REGID+“ ”);
//您的GCM推送服务器需要知道regID才能推送到此设备
//这里是您可能希望发送regID供以后使用的地方。
console.log(“regID=“+regID”);
}
打破
案例“信息”:
$(“#应用程序状态ul”).append(“消息->消息:”+e.MESSAGE+“ ”);
$(“#应用程序状态ul”).append(“消息->MSGCNT:”+e.MSGCNT+” );
打破
案例“错误”:
$(“#应用程序状态ul”).append(“错误->消息:”+e.MSG+“ ”);
打破
违约:
$(“#应用程序状态ul”).append(“事件->未知,收到了一个事件,我们不知道它是什么”);
打破
}
}
函数标记处理程序(结果){
$(“#应用程序状态ul”).append(“ 标记:“+result+” ”);
//您的iOS推送服务器需要知道令牌才能推送到此设备
//这里是您可能希望向其发送令牌以供以后使用的地方。
}
函数successHandler(结果){
$(“#应用程序状态ul”).append(“成功:“+result+” ”);
}
函数errorHandler(错误){
$(“#应用程序状态ul”).append(“错误:”+error+“ ”);
}
文件。添加的监听器('deviceready',OnDeviceraddy,true);
- Cordova PushNotification插件演示
根据Phonegap Build社区论坛,APS注册需要使用分发提供证书:
一些人在转换到生产证书后成功了。
但是,我也遇到了同样的问题,仍然无法通过生产证书使其工作。经过长时间的研究和反复试验。我发现我需要使用:
在IOS(临时设置配置文件)和推送服务器(生产aps证书和密钥)上,此处存在相同的问题。我将尝试跳过开发证书而使用生产证书。那么您找到解决方案了吗?
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery_1.5.2.min.js"></script>
<script type="text/javascript" src="PushNotification.js"></script>
<script type="text/javascript">
var pushNotification;
function onDeviceReady() {
$("#app-status-ul").append('<li>deviceready event received</li>');
pushNotification = window.plugins.pushNotification;
if (device.platform == 'android' || device.platform == 'Android') {
pushNotification.register(successHandler, errorHandler, {"senderID":"661780372179","ecb":"onNotificationGCM"});
} else {
pushNotification.register(tokenHandler, errorHandler, {"badge":"true","sound":"true","alert":"true","ecb":"onNotificationAPN"});
}
}
// handle APNS notifications for iOS
function onNotificationAPN(event) {
if (event.alert) {
$("#app-status-ul").append('<li>push-notification: ' + event.alert + '</li>');
navigator.notification.alert(event.alert);
}
if (event.sound) {
var snd = new Media(event.sound);
snd.play();
}
if (event.badge) {
pushNotification.setApplicationIconBadgeNumber(successHandler, event.badge);
}
}
// handle GCM notifications for Android
function onNotificationGCM(e) {
$("#app-status-ul").append('<li>EVENT -> RECEIVED:' + e.event + '</li>');
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
$("#app-status-ul").append('<li>REGISTERED -> REGID:' + e.regid + "</li>");
// Your GCM push server needs to know the regID before it can push to this device
// here is where you might want to send it the regID for later use.
console.log("regID = " + regID);
}
break;
case 'message':
$("#app-status-ul").append('<li>MESSAGE -> MSG: ' + e.message + '</li>');
$("#app-status-ul").append('<li>MESSAGE -> MSGCNT: ' + e.msgcnt + '</li>');
break;
case 'error':
$("#app-status-ul").append('<li>ERROR -> MSG:' + e.msg + '</li>');
break;
default:
$("#app-status-ul").append('<li>EVENT -> Unknown, an event was received and we do not know what it is</li>');
break;
}
}
function tokenHandler (result) {
$("#app-status-ul").append('<li>token: '+ result +'</li>');
// 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.
}
function successHandler (result) {
$("#app-status-ul").append('<li>success:'+ result +'</li>');
}
function errorHandler (error) {
$("#app-status-ul").append('<li>error:'+ error +'</li>');
}
document.addEventListener('deviceready', onDeviceReady, true);
</script>
<div id="app-status-div">
<ul id="app-status-ul">
<li>Cordova PushNotification Plugin Demo</li>
</ul>
</div>