Cordova: iOS: not calling pushPlugin.register, window.onNoti



pushPlugin.register函数在Android上被调用,但在iOS上没有。这是我的密码。

this.initialize正在被调用,我在那里看到了第一个警报——警报("PushNotifications:initialize");

有什么想法吗?为什么pushPlugin.register和window.onotificationAPN函数似乎没有被调用?。IIRC曾一度发挥了作用。我不确定发生了什么变化。

以下是我的配置设置:https://gist.github.com/adaptivedev/d33f38cd3d6cf10be9dc

谢谢!

.service("PushNotifications",function(Utility,$cordovaToast,$rootScope){

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;
    };
};

});

我解决了它!在Xcode中,选择文件(PushPlugin.m),并在右侧选中"目标成员资格"

相关内容

  • 没有找到相关文章

最新更新