cordova推送和本地通知冲突

时间:2015-06-12 13:34:10

标签: android ios cordova notifications push-notification

我创建了一个移动应用程序(Ionic + Cordova)。已安装Cordova Push NotificationsCordova Local-Notification Plugin但是当我收到推送通知或屏幕外,我会丢​​失所有本地通知。如果通过isScheduled函数检查它我得到TRUE。如果我删除推送通知代码

var config = null;
        if (ionic.Platform.isAndroid()) {
            config = {
                "senderID": "111111111111" // REPLACE THIS WITH YOURS FROM GCM CONSOLE - also in the project URL like: https://console.developers.google.com/project/434205989073
                //"ecb": "window.onNotificationGCM"
            }
        } else if (ionic.Platform.isIOS()) {
            config = {
                "badge": "true",
                "sound": "true",
                "alert": "true"
            }
        }

        $cordovaPush.register(config).then(function(result) {
            // ** NOTE: Android regid result comes back in the pushNotificationReceived, only iOS returned here
            if (ionic.Platform.isIOS()) {
                $rootScope.regId = result;
                scheduleNotifications.storeDeviceToken("ios");
            }
        }, function(err) {
            navigator.notification.alert("Register error " + err);
        });

它运作正常。这可能有什么问题?

2 个答案:

答案 0 :(得分:2)

我认为你很好,因为我甚至不能一起运行它们。

    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Landroid/support
    /v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfo
    VersionImpl;

Local Notification正在安装android.support.v4作为依赖项,与Ionic的其余部分冲突。

编辑:通过nuking platform / android / libs下的v4.jar文件来修复。

答案 1 :(得分:1)

这是一个解决方案 - 只需添加" clearNotifications":false以推送通知init

var push = PushNotification.init({
        "android": {
        "senderID": "114273210157",
        "clearNotifications": false
       },
       "ios": {"alert": "true", "badge": "true", "sound": "true"}
      });