2014-09-10 4 views
2

pushPlugin.register 함수가 Android에서는 호출되지만 iOS에서는 호출되지 않습니다. 여기 내가 가진 코드가있다.코도 바 : iOS : pushPlugin.register, window.onNotificaiton.APN을 호출하지 않습니다.

this.initialize가 호출되고 거기에 첫 번째 경고가 표시됩니다. - alert ('PushNotifications : initialize');

아이디어가 있으십니까? 왜 pushPlugin.register와 window.onNotificationAPN 함수가 호출되지 않는 것입니까? 간단히 말해서 IIRC가 작동하고있었습니다. 나는 무엇이 바뀌 었는지 모르겠습니다. https://gist.github.com/adaptivedev/d33f38cd3d6cf10be9dc

감사 :

여기 내 설정 설정입니다!

.service ('PushNotifications'기능 (유틸리티 $ 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; 
    }; 

}; 

});

+0

동일한 문제가 발생했습니다.이 문제가 해결 되었습니까?! – Moussawi7

+1

나는 그것을 해결했다! Xcode에서 파일 (PushPlugin.m)을 선택하고 오른쪽에서 "대상 멤버쉽" – mylord

답변

0

해결했습니다. Xcode에서 파일 (PushPlugin.m)을 선택하고 오른쪽에서 "Target Membership"을 확인하십시오.

관련 문제