2014-10-06 54 views
0

4個應用程序在蘋果商店和Android市場創建Pushwoosh + phonegap構建。通知在所有設備上都很好,除了新的ios8。爲什麼?有些改變了嗎?我用這2個文件: Pushnotification.jsNotifications with ios8 - Pushwoosh + phonegap

(function(cordova) { 

    function PushNotification() {} 

    // Call this to register for push notifications and retreive a deviceToken 
    PushNotification.prototype.registerDevice = function(config, success, fail) { 
     cordova.exec(success, fail, "PushNotification", "registerDevice", config ? [config] : []); 
    }; 

    // Call this to set tags for the device 
    PushNotification.prototype.setTags = function(config, success, fail) { 
     cordova.exec(success, fail, "PushNotification", "setTags", config ? [config] : []); 
    }; 

    // Call this to send geo location for the device 
    PushNotification.prototype.sendLocation = function(config, success, fail) { 
     cordova.exec(success, fail, "PushNotification", "sendLocation", config ? [config] : []); 
    }; 

    PushNotification.prototype.onDeviceReady = function() { 
     cordova.exec(null, null, "PushNotification", "onDeviceReady", []); 
    }; 

    // Call this to get tags for the device 
    PushNotification.prototype.getTags = function(success, fail) { 
     cordova.exec(success, fail, "PushNotification", "getTags", []); 
    }; 

    //Android Only---- 
    PushNotification.prototype.unregisterDevice = function(success, fail) { 
     cordova.exec(success, fail, "PushNotification", "unregisterDevice", []); 
    }; 

    //config params: {msg:"message", seconds:30, userData:"optional"} 
    PushNotification.prototype.createLocalNotification = function(config, success, fail) { 
     cordova.exec(success, fail, "PushNotification", "createLocalNotification", config ? [config] : []); 
    }; 

    PushNotification.prototype.clearLocalNotification = function() { 
     cordova.exec(null, null, "PushNotification", "clearLocalNotification", []); 
    }; 

    //advanced background task to track device position and not drain the battery 
    PushNotification.prototype.startGeoPushes = function(success, fail) { 
     cordova.exec(success, fail, "PushNotification", "startGeoPushes", []); 
    }; 

    PushNotification.prototype.stopGeoPushes = function(success, fail) { 
     cordova.exec(success, fail, "PushNotification", "stopGeoPushes", []); 
    }; 

    //sets multi notification mode on 
    PushNotification.prototype.setMultiNotificationMode = function(success, fail) { 
     cordova.exec(success, fail, "PushNotification", "setMultiNotificationMode", []); 
    }; 

    //sets single notification mode 
    PushNotification.prototype.setSingleNotificationMode = function(success, fail) { 
     cordova.exec(success, fail, "PushNotification", "setSingleNotificationMode", []); 
    }; 

    //type: 0 default, 1 no sound, 2 always 
    PushNotification.prototype.setSoundType = function(type, success, fail) { 
     cordova.exec(success, fail, "PushNotification", "setSoundType", [type]); 
    }; 

    //type: 0 default, 1 no vibration, 2 always 
    PushNotification.prototype.setVibrateType = function(type, success, fail) { 
     cordova.exec(success, fail, "PushNotification", "setVibrateType", [type]); 
    }; 

    PushNotification.prototype.setLightScreenOnNotification = function(on, success, fail) { 
     cordova.exec(success, fail, "PushNotification", "setLightScreenOnNotification", [on]); 
    }; 

    //set to enable led blinking when notification arrives and display is off 
    PushNotification.prototype.setEnableLED = function(on, success, fail) { 
     cordova.exec(success, fail, "PushNotification", "setEnableLED", [on]); 
    }; 

    //{goal:'name', count:3} (count is optional) 
    PushNotification.prototype.sendGoalAchieved = function(config, success, fail) { 
     cordova.exec(success, fail, "PushNotification", "sendGoalAchieved", config ? [config] : []); 
    }; 

    //Android End---- 

    //iOS only---- 
    PushNotification.prototype.startLocationTracking = function(backgroundMode, success, fail) { 
     cordova.exec(success, fail, "PushNotification", "startLocationTracking", backgroundMode ? [{mode : backgroundMode}] : []); 
    }; 

    PushNotification.prototype.stopLocationTracking = function(success, fail) { 
     cordova.exec(success, fail, "PushNotification", "stopLocationTracking", []); 
    }; 

    // Call this to get a detailed status of remoteNotifications 
    PushNotification.prototype.getRemoteNotificationStatus = function(callback) { 
     cordova.exec(callback, callback, "PushNotification", "getRemoteNotificationStatus", []); 
    }; 

    // Call this to set the application icon badge 
    PushNotification.prototype.setApplicationIconBadgeNumber = function(badgeNumber, callback) { 
     cordova.exec(callback, callback, "PushNotification", "setApplicationIconBadgeNumber", [{badge: badgeNumber}]); 
    }; 

    // Call this to clear all notifications from the notification center 
    PushNotification.prototype.cancelAllLocalNotifications = function(callback) { 
     cordova.exec(callback, callback, "PushNotification", "cancelAllLocalNotifications", []); 
    }; 
    //iOS End---- 

    // Event spawned when a notification is received while the application is active 
    PushNotification.prototype.notificationCallback = function(notification) { 
     var ev = document.createEvent('HTMLEvents'); 
     ev.notification = notification; 
     ev.initEvent('push-notification', true, true, arguments); 
     document.dispatchEvent(ev); 
    }; 

    cordova.addConstructor(function() { 
     if(!window.plugins) window.plugins = {}; 
     window.plugins.pushNotification = new PushNotification(); 
    }); 

})(window.cordova || window.Cordova || window.PhoneGap); 

而且app.js

function registerPushwooshIOS() { 
     var pushNotification = window.plugins.pushNotification; 

    //push notifications handler 
    document.addEventListener('push-notification', function(event) { 
       var notification = event.notification; 
       //navigator.notification.alert(notification.aps.alert); 

       //to view full push payload 
       //navigator.notification.alert(JSON.stringify(notification)); 

       //reset badges on icon 
       pushNotification.setApplicationIconBadgeNumber(0); 
       }); 

    pushNotification.registerDevice({alert:true, badge:true, sound:true, pw_appid:"69620-5C1D0", appname:"Maxistore"}, 
            function(status) { 
             var deviceToken = status['deviceToken']; 
             console.warn('registerDevice: ' + deviceToken); 
             onPushwooshiOSInitialized(deviceToken); 
            }, 
            function(status) { 
             console.warn('failed to register : ' + JSON.stringify(status)); 
             navigator.notification.alert(JSON.stringify(['failed to register ', status])); 
            }); 

    //reset badges on start 
    pushNotification.setApplicationIconBadgeNumber(0); 
} 

function onPushwooshiOSInitialized(pushToken) 
{ 
    var pushNotification = window.plugins.pushNotification; 
    //retrieve the tags for the device 
    pushNotification.getTags(function(tags) { 
           console.warn('tags for the device: ' + JSON.stringify(tags)); 
          }, 
          function(error) { 
           console.warn('get tags error: ' + JSON.stringify(error)); 
          }); 

    //start geo tracking. PWTrackSignificantLocationChanges - Uses GPS in foreground, Cell Triangulation in background. 
    pushNotification.startLocationTracking('PWTrackSignificantLocationChanges', 
            function() { 
              console.warn('Location Tracking Started'); 
            }); 
} 

function registerPushwooshAndroid() { 

    var pushNotification = window.plugins.pushNotification; 

    //push notifications handler 
    document.addEventListener('push-notification', function(event) { 
       var title = event.notification.title; 
       var userData = event.notification.userdata; 

       //dump custom data to the console if it exists 
       if(typeof(userData) != "undefined") { 
        console.warn('user data: ' + JSON.stringify(userData)); 
       } 

       //and show alert 
       //navigator.notification.alert(title); 

       //stopping geopushes 
       pushNotification.stopGeoPushes(); 
       }); 

    //projectid: "GOOGLE_PROJECT_ID", appid : "PUSHWOOSH_APP_ID" 
    pushNotification.registerDevice({ projectid: "863823034249", appid : "69620-5C1D0" }, 
            function(token) { 
             alert(token); 
             //callback when pushwoosh is ready 
             onPushwooshAndroidInitialized(token); 
            }, 
            function(status) { 
             alert("failed to register: " + status); 
             console.warn(JSON.stringify(['failed to register ', status])); 
            }); 
} 

function onPushwooshAndroidInitialized(pushToken) 
{ 
    //output the token to the console 
    console.warn('push token: ' + pushToken); 

    var pushNotification = window.plugins.pushNotification; 

    pushNotification.getTags(function(tags) { 
          console.warn('tags for the device: ' + JSON.stringify(tags)); 
         }, 
         function(error) { 
          console.warn('get tags error: ' + JSON.stringify(error)); 
         }); 


    //set multi notificaiton mode 
    //pushNotification.setMultiNotificationMode(); 
    //pushNotification.setEnableLED(true); 

    //set single notification mode 
    //pushNotification.setSingleNotificationMode(); 

    //disable sound and vibration 
    //pushNotification.setSoundType(1); 
    //pushNotification.setVibrateType(1); 

    pushNotification.setLightScreenOnNotification(false); 

    //goal with count 
    //pushNotification.sendGoalAchieved({goal:'purchase', count:3}); 

    //goal with no count 
    //pushNotification.sendGoalAchieved({goal:'registration'}); 

    //setting list tags 
    //pushNotification.setTags({"MyTag":["hello", "world"]}); 

    //settings tags 
    pushNotification.setTags({deviceName:"hello", deviceId:10}, 
            function(status) { 
             console.warn('setTags success'); 
            }, 
            function(status) { 
             console.warn('setTags failed'); 
            }); 

    function geolocationSuccess(position) { 
     pushNotification.sendLocation({lat:position.coords.latitude, lon:position.coords.longitude}, 
           function(status) { 
             console.warn('sendLocation success'); 
           }, 
           function(status) { 
             console.warn('sendLocation failed'); 
           }); 
    }; 

    // onError Callback receives a PositionError object 
    // 
    function geolocationError(error) { 
     alert('code: ' + error.code + '\n' + 
       'message: ' + error.message + '\n'); 
    } 

    function getCurrentPosition() { 
     navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError); 
    } 

    //greedy method to get user position every 3 second. works well for demo. 
// setInterval(getCurrentPosition, 3000); 

    //this method just gives the position once 
// navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError); 

    //this method should track the user position as per Phonegap docs. 
// navigator.geolocation.watchPosition(geolocationSuccess, geolocationError, { maximumAge: 3000, enableHighAccuracy: true }); 

    //Pushwoosh Android specific method that cares for the battery 
    pushNotification.startGeoPushes(); 
} 

function initPushwoosh() { 
    var pushNotification = window.plugins.pushNotification; 
    if(device.platform == "Android") 
    { 
     registerPushwooshAndroid(); 
     pushNotification.onDeviceReady(); 
    } 

    if(device.platform == "iPhone" || device.platform == "iOS") 
    { 
     registerPushwooshIOS(); 
     pushNotification.onDeviceReady(); 
    } 
} 

回答

0

在iOS8上的改變時,推送通知界面。如果您的第三方庫尚未更新以適應,推送通知可能會失敗。

背景:

-[UIApplication registerUserNotificationSettings:] 
-[UIApplication registerForRemoteNotifications] 
+0

TNX的回答,我用的PhoneGap的最後一個版本...所以我認爲錯誤是在2個文件我用。沒人能幫助我? – user1726972 2014-10-06 15:45:58

0

在pushwoosh post

請看:
此前,登記的通知與

-[UIApplication registerForRemoteNotificationTypes:] 

由於iOS8上的進行,但現在做

由於對iOS 8的多重支持請求,我們認爲在我們的博客中也可以看到一些亮點。目前,Pushwoosh iOS SDK有兩種版本:

iOS 7 SDK - 必須使用Xcode v.5編譯 - 不支持iOS 8中引入的最新功能;

的iOS 8 SDK - 必須在Xcode .6編譯

因此,在Xcode中第5節的iOS 7 SDK編譯的應用程序將繼續在設備上運行iOS 8,由於其兼容性正常工作。如果您使用Pushwoosh iOS 8 SDK,則必須使用Xcode v.6編譯您的應用程序。

你可以下載here