2015-05-27 18 views
10

Ho dedicato molto tempo a trovare il plug-in Cordova corretto per le notifiche push parse per entrambe le piattaforme iOS Android &.Plug-Push Parse-Push Cordova/PhoneGap per iOS

miei requisiti sono:

  1. Per ricevere una notifica parse push (sia Android & iOS)
  2. In grado di memorizzare tutte le notifiche push in arrivo cellulare Sqlite memoria locale.

Ho provato tutti i plug-in push cordova di seguito per entrambe le piattaforme iOS Android &.

  1. https://github.com/avivais/phonegap-parse-plugin
  2. https://github.com/taivo/parse-push-plugin
  3. https://github.com/campers/parse-push-plugin
  4. https://github.com/manishiitg/parse-push-plugin

Per Android: Tutti i plugin di cui sopra stanno lavorando perfettamente per soddisfare le mie esigenze di cui sopra.

Per iOS: Solo 1 ° plug cioè https://github.com/avivais/phonegap-parse-plugin sta lavorando. E anche questo non ero in grado di salvare le notifiche in sqlite di archiviazione locale. Ciò significa che solo il mio primo requisito è soddisfatto, ma non il mio secondo requisito.

Tutte le pagine GitHub di plugin rimanenti (cioè 2 °, 3 °, 4 °) afferma che:

"Si prega di notare che ho lavorato solo sull'aspetto Android di questa forcella Il lato iOS non è ancora. aggiornato."

C'è qualche plug-in che funzionerà con entrambe le piattaforme Android & per soddisfare i miei 2 requisiti?

(o)

Se non ci sono plug-in comune per entrambe le piattaforme, allora come posso conservare i plugin in entrata in iOS SQLite?

Per favore aiutatemi. Grazie in anticipo.

+2

Si prega di dare i motivi per cui si è giù votando questa domanda? – Sivakumar

+2

È strano che quattro utenti abbiano messo in downvoted questo post e non ne abbia indicato il motivo. Per favore, ti prego di spiegare. –

+1

@Mr_Green sì, le persone dovrebbero essere abbastanza responsabili da spiegare perché sono giù a votare un post – Strikers

risposta

3

mi capita di mantenere https://github.com/taivo/parse-push-plugin

Sembra che hai preso la forchetta alla sua infanzia. L'ho preso quando la forcella a monte sembrava stagnante per un po 'e in quel momento stavo solo affrontando l'aspetto di Android. Da allora ho fornito il supporto completo per iOS. E funziona per parse-server e per lo parse.com uscente. Ho fatto anche una migliore e ha fatto l'installazione solo una questione di

cordova add https://github.com/taivo/parse-push-plugin 

e scrivere qualche config.xml tag per indicare URL del server, e App ID.

Questo dovrebbe eliminare il grosso problema di dover manomettere manualmente Android Manifest, Java e Objective C durante la configurazione del plug-in.

Ora dovrebbe soddisfare o superare il requisito. Per ricevere notifiche push e memorizzare in sqlite, tutto ciò che devi fare è impostare un gestore di eventi in javascript. Assicurati di avvolgerlo con un tipo di dispositivo pronto per l'uso o con un gestore di eventi pronto per la piattaforma per assicurarti che il plugin sia stato caricato correttamente.

$ionicPlatform.ready(function(){ 
    if(window.ParsePushPlugin){ 
     ParsePushPlugin.on('receivePN', function(pn){ 
      console.log('yo i got this notif:' + JSON.stringify(pn)); 

      // 
      // do your sqlite storage here 
      // 
     }); 
    } 
}); 
1

Potresti essere interessato allo Azure Push Notifications. Combina entrambi i servizi di notifica Push in modo da poter inviare messaggi a entrambi i dispositivi da un punto centrale.

cito:

Notifica hub una soluzione scalabile, soluzione multi-piattaforma per l'invio di spinta notifiche ai dispositivi mobili, i mozzi di notifica funziona bene con Cordova applicazioni. Gli hub di notifica gestiscono le registrazioni con ogni PNS . Più importante, Hub di notifica consente di creare le registrazioni del modello in modo da poter inviare messaggi a tutti i dispositivi registrati, indipendentemente dalla piattaforma, con solo una singola riga di codice.Puoi anche utilizzare i tag per inviare notifiche mirate solo ai dispositivi con registrazioni specifiche . Per ulteriori informazioni su Hub di notifica, consultare il sito Web di Azure all'indirizzo aka.ms/nkn4n4.

Qui ho una classe di supporto per la registrazione del dispositivo con il servizio di pushnotification. Per l'invio di notifiche push, è possibile utilizzare un portale azzurro e inviare notifiche push in stile in formato json.

var Pushman = { 

    Initialize: function (hubConnString, hubName, gcmSenderId, callbackRegistered, callbackUnRegistered, callbackInlineNotification, callbackBackgroundNotification, callbackError) { 

     //store connection and callback information on app startup for Push Registration later 
     Pushman.HubConnectionString = hubConnString; 
     Pushman.HubName = hubName; 
     Pushman.GcmSenderId = gcmSenderId; 

     //callbacks 
     Pushman.RegisteredCallback = callbackRegistered; 
     Pushman.UnRegisteredCallback = callbackUnRegistered; 
     Pushman.NotificationForegroundCallback = callbackInlineNotification; 
     Pushman.NotificationBackgroundCallback = callbackBackgroundNotification; 
     Pushman.ErrorCallback = callbackError; 

    }, 

    RegisterForPushNotifications: function (tags) { 
     //setup Azure Notification Hub registration 
     Pushman.Hub = new WindowsAzure.Messaging.NotificationHub(Pushman.HubName, Pushman.HubConnectionString, Pushman.GcmSenderId); 
     Pushman.Hub.registerApplicationAsync(tags).then(Pushman.onRegistered, Pushman.onError); 

     //setup PushPlugin registration 
     Pushman.Push = window.PushNotification; 
     var push; 

     //register depending on device being run 
     if (device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos") { 

      //android 

      push = Pushman.Push.init(
       { "android": { "senderID": Pushman.GcmSenderId } } 
      ); 
      push.on('registration', Pushman.onRegistered); 
      push.on('notification', Pushman.onAndroidNotification); 
      push.on('error', Pushman.onError); 


     } else { 

      //iOS 
      push = Pushman.Push.init(
       { "ios": { "alert": "true", "badge": "true", "sound": "true" } } 
       ); 

      push.on('registration', Pushman.onRegistered); 
      push.on('notification', Pushman.onIOSNotification); 
      push.on('error', Pushman.onError); 

     } 
    }, 

    UnRegisterForPushNotifications: function() { 

     if (Pushman.Hub != null) { 

      //dont pass through error handler 

      //unreg azure 
      Pushman.Hub.unregisterApplicationAsync() 
       .then(Pushman.onUnRegistered, null); 

      //unreg native 
      Pushman.Push.unregister(Pushman.onUnRegistered, null); 

     } 

    }, 

    onRegistered: function (msg) { 
     Pushman.log("Registered: " + msg.registrationId); 

     //only call callback if registrationId actually set 
     if (msg.registrationId.length > 0 && Pushman.RegisteredCallback != null) { 
      Pushman.RegisteredCallback(msg); 
     } 
    }, 

    onUnRegistered: function() { 
     Pushman.log("UnRegistered"); 

     if (Pushman.UnRegisteredCallback != null) { 
      Pushman.UnRegisteredCallback(); 
     } 
    }, 

    onInlineNotification: function (msg) { 
     Pushman.log("OnInlineNotification: " + msg); 

     if (Pushman.NotificationForegroundCallback != null) { 
      Pushman.NotificationForegroundCallback(msg); 
     } 
    }, 

    onBackgroundNotification: function (msg) { 
     Pushman.log("OnBackgroundNotification: " + msg); 

     if (Pushman.NotificationBackgroundCallback != null) { 
      Pushman.NotificationBackgroundCallback(msg); 
     } 
    }, 

    onColdStartNotification: function (msg) { 
     Pushman.log("OnColdStartNotification: " + msg); 

     if (Pushman.NotificationBackgroundCallback != null) { 
      Pushman.NotificationBackgroundCallback(msg); 
     } 
    }, 

    onError: function (error) { 
     Pushman.log("Error: " + error); 

     if (Pushman.ErrorCallback != null) { 
      Pushman.ErrorCallback(error); 
     } 
    }, 

    onAndroidNotification: function (e) { 

     switch (e.event) { 
      case 'registered': 

       if (e.regid.length > 0) { 
        Pushman.onRegistered("Registered"); 
       } 
       break; 

      case 'message': 

       if (e.foreground) { 

        //if this flag is set, this notification happened while app in foreground 
        Pushman.onInlineNotification(e.payload.message); 

       } else { 

        //otherwise app launched because the user touched a notification in the notification tray. 
        if (e.coldstart) { 
         //app was closed 
         Pushman.onColdStartNotification(e.payload.message); 
        } 
        else { 
         //app was minimized 
         Pushman.onBackgroundNotification(e.payload.message); 
        } 
       } 
       break; 

      case 'error': 
       Pushman.onError(e.msg); 
       break; 

      default: 
       Pushman.onError("Unknown message"); 
       break; 
     } 
    }, 

    onIOSNotification: function (event) { 

     //TODO: not sure how ios works re cold start vs inline msg types? 

     if (event.alert) { 
      navigator.notification.alert(event.alert); 
     } 
     if (event.badge) { 
      Push.setApplicationIconBadgeNumber(app.successHandler, app.errorHandler, event.badge); 
     } 
    }, 

    tokenHandler: function (result) { 
     // iOS - not sure its use though appears somewhat important 

     // Your iOS push server needs to know the token before it can push to this device 
     // here is where you might want to send it the token for later use. 
     alert('device token = ' + result); 

    }, 

    log: function (msg) { 
     console.log(msg); 
    }, 

} 

///"class" variables - not sure how to put them into the js "class" 
Pushman.Push = null; 
Pushman.Hub = null; 
Pushman.HubConnectionString = null; 
Pushman.HubName = null; 
Pushman.GcmSenderId = null; 
Pushman.NotificationForegroundCallback = null; 
Pushman.NotificationBackgroundCallback = null; 
Pushman.RegisteredCallback = null; 
Pushman.UnRegisteredCallback = null; 
Pushman.ErrorCallback = null; 

non ho scritto io stesso, tutto il merito va a this guy.

Poi basta inizializzare il plugin quando l'applicazione viene avviata:

//azure notificationshub connection information 
notificationHubPath = "notificationhub name"; 
connectionString = "notificatin hub connectionstring"; 
//sender id for google cloud services 
var senderIdGCM = "sender id from google gcm"; 
//tag registration (csv string), can be empty but not undefined 
var registrationTagsCsv = ""; //test1, test2 

var app = { 

    Initialize: function() { 
     //reg for onload event 
     this.AppStart(); 
    }, 

    AppStart: function() { 
     "use strict"; 
     document.addEventListener('deviceready', app.onLoad, false); 
     document.addEventListener('deviceready', onDeviceReady.bind(this), false); 

     function onDeviceReady() { 
      // Handle the Cordova pause and resume events 
      document.addEventListener('pause', onPause.bind(this), false); 
      document.addEventListener('resume', onResume.bind(this), false); 

      // TODO: Cordova has been loaded. Perform any initialization that requires Cordova here. 
     }; 

     function onPause() { 
      // TODO: This application has been suspended. Save application state here. 
     }; 

     function onResume() { 
      // TODO: This application has been reactivated. Restore application state here. 
     }; 
    }, 

    onLoad: function() { 

     app.log("Initializing..."); 

     //setup push notifications 
     Pushman.Initialize(connectionString, notificationHubPath, senderIdGCM, 
          app.onNotificationRegistered, app.onNotificationUnRegistered, 
          app.onNotificationInline, app.onNotificationBackground, app.onNotificationError); 

     //hookup cmd buttons 
     app.registerForPush(); 
     //$("#register").click(app.registerForPush); 
     //$("#unregister").click(app.unRegisterForPush); 

     app.onAppReady(); 
    }, 

    registerForPush: function (a, c) { 

     app.log("Registering..."); 
     //register for tags 
     Pushman.RegisterForPushNotifications(registrationTagsCsv); 

    }, 

    unRegisterForPush: function (a, c) { 

     app.log("UnRegistering..."); 
     //register for tags 
     Pushman.UnRegisterForPushNotifications(); 

    }, 

    onAppReady: function() { 
     app.log("Ready"); 
    }, 

    onNotificationRegistered: function (msg) { 
     app.log("Registered: " + msg.registrationId); 
    }, 

    onNotificationUnRegistered: function() { 
     app.log("UnRegistered"); 
    }, 

    onNotificationInline: function (data) { 
     app.log("Inline Notification: " + data); 
    }, 

    onNotificationBackground: function (data) { 
     app.log("Background Notification: " + data); 
    }, 

    onNotificationError: function (error) { 
     app.log("Error: " + error); 
    }, 

    log: function (msg) { 
     console.log(msg); 
    }, 

}; 

Se si desidera memorizzare i messaggi Poi basta aggiungere il codice per l'archiviazione di SQL in cui i messaggi vengono ricevuti. Avrai bisogno di un account azzurro per farlo funzionare, here è possibile ottenere un percorso gratuito. Ti consentirà di inviare fino a 1 milione di notifiche push al mese gratuitamente.

+0

Aiuto massiccio, uno dei pochi post che lo spiega chiaramente usando gli Hub di notifica – GONeale