Monday, 25 March 2019

Extending Firebase notifications from Web app to Mobile app

I have a website that uses notifications to users (on browsers) that go via Firebase, and this is working well.

I now have an Android App that someone developed for me, which basically houses the web site (via webView) along with some additional tools such as a QR reader. I myself am not an app developer but a web dev.

I would like to add the notifications to the App as well - he told me he has added what he needs to do on his side (in the app - via phonegap, I think), and that I need to add some code to the web site, so that that the notifications can work in the App as well. Does this make sense to anyone? Can anyone shed some light on this for me? I thought half the point of Firebase was that it's platform-wide.

Here is some config info that I have from the Firebase Console for the web:

// Initialize Firebase
  var config = {
    apiKey: "AIzaSyBXXXXXXXXXXXXXXXXXXXXXXXXXXXX,
    authDomain: "doi-18XXXXXX.firebaseapp.com",
    databaseURL: "https://doi-18XXXXXX.firebaseio.com",
    projectId: "doi-18XXXXXX",
    storageBucket: "doi-18XXXXXX.appspot.com",
    messagingSenderId: "36XXXXXXX"
  };
  firebase.initializeApp(config);

And this is the google-services.json which I gave to the app developer (NOT on the website)

{
  "project_info": {
    "project_number": "36XXXXXX",
    "firebase_url": "https://doi-18XXXXXX.firebaseio.com",
    "project_id": "doi-18XXXXXX",
    "storage_bucket": "doi-18XXXXXX.appspot.com"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "1:36XXXXXXXXX:android:9e2XXXXXXX",
        "android_client_info": {
          "package_name": "com.doi.org"
        }
      },
      "oauth_client": [
        {
          "client_id": "36XXXXXX-4XXXXXXXXXikpb8r3.apps.googleusercontent.com",
          "client_type": 3
        }
      ],
      "api_key": [
        {
          "current_key": "AIzaSyBXXXXXXXXXXXXXXXXXXXXXx"
        }
      ],
      "services": {
        "analytics_service": {
          "status": 1
        },
        "appinvite_service": {
          "status": 1,
          "other_platform_oauth_client": []
        },
        "ads_service": {
          "status": 2
        }
      }
    }
  ],
  "configuration_version": "1"
}

And this is my server-side code (VBScript) that successfully sends notifications (currently only to web destinations):

posturl="https://fcm.googleapis.com/fcm/send"

body= "{ ""notification"": {"
body=body & """title"": """ & replace(messageTitle, """", "\""") & ""","
body=body & """body"": """ & replace(messageContent, """", "\""") & ""","
body=body & """icon"": ""/images/favicons/apple-touch-icon-60x60.png"","
body=body & """click_action"": """ & link & ""","
body=body & "},"
body=body & """to"" : """ & token & """}"

set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST",posturl,false
xmlhttp.setRequestHeader "Content-Type", "application/json"
xmlhttp.setRequestHeader "Authorization", "key=AAAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

xmlhttp.send body
result= xmlhttp.responseText
SendFirebaseMessage = result
Set xmlhttp = nothing   

So... very confused - is he correct, that something needs to be added on my end somewhere? Thanks!



from Extending Firebase notifications from Web app to Mobile app

No comments:

Post a Comment