2015-05-27 11 views
10

मैं समय के बहुत खर्च किया है दोनों एंड्रॉयड & आईओएस प्लेटफॉर्म के लिए पार्स पुश नोटिफिकेशन के लिए सही कॉर्डोबा प्लगइन खोजने के लिए।Cordova/Phonegap आईओएस पार्स-पुश प्लगइन

मेरे आवश्यकताएँ हैं:

  1. (दोनों एंड्रॉयड & आईओएस में) पार्स धक्का अधिसूचना प्राप्त करने के
  2. मोबाइल स्थानीय भंडारण SQLite में आने वाले सभी पुश नोटिफिकेशन के स्टोर कर।

मैं दोनों एंड्रॉयड & आईओएस प्लेटफॉर्म के लिए सभी नीचे पार्स धक्का कॉर्डोबा प्लगइन्स की कोशिश की है।

  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

Android के लिए: उपरोक्त सभी प्लगइन्स मेरे ऊपर उल्लेख किया है आवश्यकताओं को पूरा करने को पूरी तरह से काम कर रहे हैं।

आईओएस के लिए: केवल 1 प्लगइन i.e https://github.com/avivais/phonegap-parse-plugin काम कर रहा है। और वह भी मैं स्थानीय भंडारण स्क्लाइट में अधिसूचनाओं को सहेजने में सक्षम नहीं था। इसका मतलब है कि केवल मेरी पहली आवश्यकता पूरी हो गई है, लेकिन मेरी दूसरी आवश्यकता नहीं है।

शेष प्लग इन की सभी GitHub पृष्ठों (यानी 2nd, 3rd, 4) के अनुसार:

"कृपया ध्यान दें कि मैं केवल इस कांटा के एंड्रॉयड पहलू पर काम किया है आईओएस ओर अभी तक नहीं है। आधुनिक।"

क्या कोई प्लगइन है जो एंड्रॉइड & आईओएस प्लेटफ़ॉर्म दोनों के लिए मेरी 2 आवश्यकताओं को पूरा करने के लिए काम करेगा?

(या)

अगर वहाँ दोनों प्लेटफार्मों के लिए कोई आम प्लगइन है, तो मैं कैसे आईओएस SQLite में भेजे प्लगइन्स स्टोर कर सकते हैं?

कृपया मेरी मदद करें। अग्रिम में धन्यवाद।

+2

कृपया कारण बताएं कि आप इस सवाल का मतदान क्यों कर रहे हैं? – Sivakumar

+2

यह अजीब बात है कि चार उपयोगकर्ताओं ने इस पोस्ट को कम किया और कारण नहीं बताया। कृपया समझाने की देखभाल करें। –

+1

@Mr_Green हां, लोगों को यह बताने के लिए ज़िम्मेदार होना चाहिए कि वे – Strikers

उत्तर

3

मैं बनाए रखने के लिए की तरह आप अपनी प्रारंभिक अवस्था में मेरी कांटा पकड़ा https://github.com/taivo/parse-push-plugin

ऐसा लगता है कि ऐसा हो रहा है। मैंने इसे उठाया जब अपस्ट्रीम कांटा थोड़ी देर के लिए स्थिर लग रहा था और उस समय मैं केवल एंड्रॉइड पहलू को संबोधित कर रहा था। तब से मैंने पूर्ण आईओएस समर्थन प्रदान किया है। और यह parse-server के साथ-साथ parse.com के लिए काम करता है। मैं भी एक बेहतर किया और स्थापना

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

का मामला और सर्वर यूआरएल इंगित करने के लिए कुछ config.xml टैग लिखने, और ऐप्स आईडी बना दिया।

प्लगइन स्थापित करते समय इसे मैन्युअल रूप से एंड्रॉइड मैनिफेस्ट, जावा और ऑब्जेक्टिव सी के साथ गड़बड़ करने का बड़ा दर्द लेना चाहिए।

अब यह आपकी आवश्यकता को पूरा या पार करना चाहिए। एसक्लाइट में पुश अधिसूचना और स्टोर प्राप्त करने के लिए, आपको बस जावास्क्रिप्ट में इवेंट हैंडलर सेट करना है। प्लगइन को ठीक से लोड करने के लिए यह सुनिश्चित करने के लिए इसे किसी प्रकार के डिवाइस तैयार या प्लेटफ़ॉर्म तैयार ईवेंट हैंडलर से लपेटना सुनिश्चित करें।

$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

तुम बस Azure Push Notifications में रुचि हो सकती। यह पुश अधिसूचना सेवाओं दोनों को जोड़ती है ताकि आप एक केंद्रीय बिंदु से दोनों उपकरणों को संदेश भेज सकें।

मैं बोली:

अधिसूचना केन्द्रों मापनीय, पार मंच मोबाइल उपकरणों के लिए धक्का भेजने सूचनाओं के लिए समाधान, सूचना केन्द्रों के साथ Cordova एप्लिकेशन अच्छी तरह से काम करता है। अधिसूचना केन्द्रों प्रत्येक पीएन साथ पंजीकरण प्रबंधन करता है। अधिक महत्वपूर्ण है, अधिसूचना केन्द्रों आप संदेशों सभी पंजीकृत उपकरणों के लिए, भले ही मंच के, केवल कोड की एक लाइन के साथ भेज सकते हैं टेम्पलेट पंजीकरण बना सकते हैं।आप विशिष्ट टैग पंजीकरण वाले डिवाइस पर केवल लक्षित सूचनाएं भेजने के लिए टैग का उपयोग कर सकते हैं। अधिसूचना केंद्रों के बारे में अधिक जानकारी के लिए, Azure वेबसाइट को aka.ms/nkn4n4 पर देखें।

यहां मेरे पास पुशोटोटिफिकेशन सेवा के साथ आपके डिवाइस को पंजीकृत करने के लिए एक सहायक वर्ग है। पुश नोटिफिकेशन भेजने के लिए, आप एक एज़ूर पोर्टल का उपयोग कर सकते हैं और जेसन प्रारूप में स्टाइल पुश नोटिफिकेशन भेज सकते हैं।

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; 

मैं इस अपने आप को नहीं लिखा था, सभी क्रेडिट this guy को जाता है।

//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); 
    }, 

}; 

आप संदेशों को संग्रहीत करना चाहते हैं तो आप बस जहां संदेश प्राप्त हो SQL के भंडारण के लिए अपने कोड जोड़ने की जरूरत:

तो फिर तुम बस जब आवेदन शुरू होता है प्लगइन प्रारंभ करने की जरूरत है। इस काम को करने के लिए आपको एक एज़ूर अकाउंट की आवश्यकता होगी, here आप एक मुफ्त निशान प्राप्त कर सकते हैं। यह आपको एक महीने में 1 मिलियन पुश अधिसूचनाएं मुफ्त में भेजने की अनुमति देगा।

+0

भारी सहायता, कुछ पदों में से एक जो स्पष्ट रूप से अधिसूचना हब्स का उपयोग करके बताती है – GONeale

0

मुझे लगता है कि इस लेख काम का हो सकता है, यह अपने संकर अनुप्रयोग के लिए एक सीधा देशी वैकल्पिक हल के अधिक

http://www.hiddentao.com/archives/2015/04/10/parse-push-notifications-for-your-android-and-ios-cordova-app/ काम करने के लिए है।

मैं एक Cordova Android एप्लिकेशन पर काम कर रहा हूँ, और यह एक काम कर समाधान

संबंधित मुद्दे