Cordova:iOS:不调用pushPlugin.register、window.onNotificaiton.APN

Cordova:iOS:不调用pushPlugin.register、window.onNotificaiton.APN,ios,cordova,ionic-framework,phonegap-pushplugin,Ios,Cordova,Ionic Framework,Phonegap Pushplugin,Android系统调用了pushPlugin.register函数,但iOS系统没有调用。这是我的密码 正在调用this.initialize,我在那里看到第一个警报--alert('PushNotifications:initialize') 有什么想法吗?为什么pushPlugin.register和window.onNotificationAPN函数似乎没有被调用?。在一个短暂的时刻,它起了作用,IIRC。我不确定是什么改变了 以下是我的配置设置: 谢谢 .service('PushNo

Android系统调用了pushPlugin.register函数,但iOS系统没有调用。这是我的密码

正在调用this.initialize,我在那里看到第一个警报--alert('PushNotifications:initialize')

有什么想法吗?为什么pushPlugin.register和window.onNotificationAPN函数似乎没有被调用?。在一个短暂的时刻,它起了作用,IIRC。我不确定是什么改变了

以下是我的配置设置:

谢谢

.service('PushNotifications',函数(实用程序,$cordovatose,$rootScope){

警报(“推送通知”);
var-pushPlugin=null;
/*
this.deviceRegId=函数(){
$rootScope.getFDeviceId();
}
*/  
this.initialize=函数(){
警报(“推送通知:初始化”);
document.addEventListener('deviceready',function(){
//警报('PushNotifications:initialize:devicerady:device='+JSON.stringify(device));
pushPlugin=window.plugins.pushNotification;
如果(device.platform==“android”| | device.platform==“android”| | device.platform==“amazon fireos”){
pushPlugin.register(
函数(结果){
log('PushNotifications:initialize:1:result='+result);
},
功能(结果){
警报('PushNotifications:initialize:2:result='+结果);
log(JSON.stringify(result));
},
{
“senderID”:“123”,
“ecb”:“通知GCM”
});
}否则{
pushPlugin.register(
功能(结果){
警报('PushNotifications:initialize:1:result='+结果);
//$rootScope.setDeviceId(结果)
},
功能(结果){
警报('PushNotifications:initialize:2:result='+结果);
log(JSON.stringify(result));
},
{
“徽章”:“真实”,
“声音”:“真实”,
“警报”:“正确”,
“欧洲央行”:“通知”
});
}
});
//Android的通知
window.onNotificationGCM=函数(e){
警报('onNotificationGCM:e='+JSON.stringify(e));
window.boosterNotification=e;
开关(如事件)
{
“已登记”案件:
如果(e.regid.length>0)
{
$rootScope.setDeviceId(e.regid);
}
打破
案例“信息”:
//如果设置了此标志,则此通知发生在我们在前台时。
//你可能想要播放一个声音来引起用户的注意,弹出一个对话框,等等。
如果(如前景)
{
//在Android上,soundname不在有效负载范围内。
//在Amazon FireOS上,所有自定义属性都包含在有效负载中
var soundfile=e.soundname | | e.payload.sound;
//如果通知包含声音名称,请播放它。
//var my_media=新媒体(“/android_资产/www/”+声音文件);
//我的媒体播放();
}
其他的
{//否则,我们将启动,因为用户触摸了通知托盘中的通知。
如果(如coldstart)
{
//
}
其他的
{
//
}
}
var msg=e.payload.message.replace(//g,“”)
msg=msg.replace(//g,“”);
$cordovatose.showShortCenter(msg).then(函数)(成功){
//$state.go('app.uncoming');
$rootScope.updateNotifications();
},函数(错误){
//错误
}
);
//警报(如有效载荷信息);
//仅适用于GCM
//e.payload.msgcnt+“”);
//仅适用于Amazon Fire操作系统
//有效载荷。时间戳
打破
案例“错误”:
//e、 味精
打破
违约:
//不为人知
打破
}
};
//iOS的通知
window.onNotificationAPN=函数(结果){
警报('onNotificationAPN:result:1:='+JSON.stringify(结果));
如果(event.alert)
{
//navigator.notification.alert(event.alert);
}
if(event.sound)
{
//var snd=新媒体(事件声音);
//snd.play();
}
如果(event.badge)
{
//.SetApplicationBadgeNumber(successHandler、errorHandler、event.badge);
}
log('onNotificationAPN:result='+JSON.stringify(result));
window.boosterNotification=结果;
};
};

}))

我解决了!在Xcode中,选择文件(PushPlugin.m)并在右侧选中“目标成员身份”

我面临同样的问题,你解决了这个问题吗?!我解决了!在Xcode中,选择文件(PushPlugin.m)并在右侧选中“目标成员资格”
alert('PushNotifications');

var pushPlugin = null;

/*
this.deviceRegId = function() {
    $rootScope.getFDeviceId();
}
*/  

this.initialize = function() {

    alert('PushNotifications:initialize');
    document.addEventListener('deviceready', function() {
        //alert('PushNotifications:initialize:deviceready:device='+JSON.stringify(device));
        pushPlugin = window.plugins.pushNotification;

        if ( device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos" ){
            pushPlugin.register(
                function(result) {          
                    console.log('PushNotifications:initialize:1:result='+result);
                },
                function(result) {
                    alert('PushNotifications:initialize:2:result='+result);
                    console.log(JSON.stringify(result));
                },
                {
                    "senderID":"123",
                    "ecb":"onNotificationGCM"
                });
        } else {
            pushPlugin.register(
                function(result) {
                    alert('PushNotifications:initialize:1:result='+result);
                    //$rootScope.setDeviceId(result)
                },
                function(result) {
                    alert('PushNotifications:initialize:2:result='+result);
                    console.log(JSON.stringify(result));
                },
                {
                    "badge":"true",
                    "sound":"true",
                    "alert":"true",
                    "ecb":"onNotificationAPN"
                });
        }

    });

    // notifications for Android
    window.onNotificationGCM = function(e) {
        alert('onNotificationGCM:e='+JSON.stringify(e));
        window.boosterNotification = e;                     
        switch( e.event )
        {
        case 'registered':
            if ( e.regid.length > 0 )
            {
              $rootScope.setDeviceId(e.regid);
            }
        break;

        case 'message':
            // if this flag is set, this notification happened while we were in the foreground.
            // you might want to play a sound to get the user's attention, throw up a dialog, etc.
            if ( e.foreground )
            {
                // on Android soundname is outside the payload. 
                // On Amazon FireOS all custom attributes are contained within payload
                var soundfile = e.soundname || e.payload.sound;
                // if the notification contains a soundname, play it.
                //var my_media = new Media("/android_asset/www/"+ soundfile);
                //my_media.play();
            }
            else
            {  // otherwise we were launched because the user touched a notification in the notification tray.
                if ( e.coldstart )
                {
                    //
                }
                else
                {
                    //
                }
            }

            var msg = e.payload.message.replace(/<b>/g, "")
            msg = msg.replace(/<\/b>/g, "");
            $cordovaToast.showShortCenter(msg).then(function(success) {
                    //$state.go('app.upcoming');
                    $rootScope.updateNotifications();
                  }, function (error) {
                    // error
                }
            );
           //alert(e.payload.message); 
           //Only works for GCM
           // e.payload.msgcnt + '</li>');
           //Only works on Amazon Fire OS
           // e.payload.timeStamp
        break;

        case 'error':
            //e.msg 
        break;

        default:
            // Unknown
        break;
      }
    };

    // notifications for iOS
    window.onNotificationAPN = function(result) {
        alert('onNotificationAPN:result:1:='+JSON.stringify(result));

        if ( event.alert )
        {
            //navigator.notification.alert(event.alert);
        }

        if ( event.sound )
        {
            //var snd = new Media(event.sound);
            //snd.play();
        }

        if ( event.badge )
        {
            //.setApplicationIconBadgeNumber(successHandler, errorHandler, event.badge);
        }

        console.log('onNotificationAPN:result='+JSON.stringify(result));

        window.boosterNotification = result;
    };

};