WordPress Plugins by Muralidharan indiacitys.com technologies

Integrate Push notification for Post & BuddyPress WP in mobile app webview

Viewing 1 post (of 1 total)
  • Author
  • #373

    Following changes are in this plugin from version 1.36 to integrate push notification for post and Buddypress plugin with native/hybrid mobile app which are using webview. So that push notification from this wordpress plugin will also be sent to native mobile app users.

    Steps to Integrate Push notification for Post and BuddyPress WordPress in mobile app webview to get tokens from mobile app webview and to send push notification to app users

    In Firebase, separate Android app needs to be created. It will create google-services.json, we need to store google-services.json in android->app folder in flutter app to get Firebase credentials for Android app using this file

    1. Go to Api to integrate mobile app tab in wordpress plugin settings and Generate secret key to communicate between mobile app(in Integrate app api tab plugin settings)

    2. use REST api to send subscription token from Mobile Flutter/native app using WebView to this WordPress plugin to store it in WordPress db to send push notification whenever new activities/post are published.

    REST API using POST method, to send push notification is designed in secured way using AES 256 cryptography encryption method to avoid spams

    REST API url post method to get subscription token from app users to send push notification

    Input parameters in body in http post method in Flutter APP,
    token – it should be encrypted as described below,

    Using secret key generated from step 1, enter secret key in flutter app code

    store token in global variable for other user
    Generate encrypted token as mentioned below using below coding (AES 256 cryptography encryption)
    Once plugin receives this token, it will unencrypt using the secret key generate and compare hash code to confirm it is sent from Flutter app

    Flutter app example code
    (I have given below example for Flutter app, you need design similar code for other native apps like Kotlin or hybrid apps using AES 256 encrytion)

    String strPwd = "16234hgJKLmllpdcd09b2bc37293"; //secret key generated in step 1 above

    GlobalData.pushtoken = token.toString();

    final iv = EncryptPack.IV.fromLength(16);

    final key = EncryptPack.Key.fromUtf8(strPwd); //hardcode

    final encrypter = EncryptPack.Encrypter(EncryptPack.AES(key, mode: EncryptPack.AESMode.cbc));

    final encrypted = encrypter.encrypt(token.toString(), iv: iv);

    var hmacSha256 = CryptoPack.Hmac(CryptoPack.sha256,ConvertPack.utf8.encode(strPwd)); // HMAC-SHA256

    var hmacstring = hmacSha256.convert(ConvertPack.utf8.encode(token.toString()));

    var encryptedsubscription = encrypted.base64+":"+iv.base64+":"+hmacstring.toString()+":"+hmacstring.toString();

    Example for Kotlin code

    val decodedsecretkey = secretkey
    val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
    val keySpec = SecretKeySpec(decodedsecretkey, "AES")
    val iv = ByteArray(16)
    val ivSpec = IvParameterSpec(iv)
    cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec)
    val result = cipher.doFinal(token.toString().toByteArray())
    val finalresult = Base64.encodeToString(result, Base64.DEFAULT)
    val hashkey = BpHmacSha256.hashstr(secretkey)
    val hmacstring = BpHmacSha256.hmacSHA256(hashkey.toByteArray(),finalresult)
    val finalresultiv = finalresult+":"+ Base64.encodeToString(iv, Base64.DEFAULT)+":"+ Base64.encodeToString(hmacstring, Base64.DEFAULT)+":"+ Base64.encodeToString(hmacstring, Base64.DEFAULT)

    Using above code generate encrypted subscription token from mobile app user who subscribed for push notification and send it to this wordpress plugin from Flutter mobile app/native app using REST api POST METHOD(http post method) https://domainname.com/wp-json/PNFPBpush/v1/subscriptiontoken. This wordpress plugin receives the token, it will store it in WordPress database.

    Now token is stored in WordPress database. So, when new activities or post is published, you will get notification in mobile app/native app/flutter app also along with website notification. Please note currently logic is included to notify only background push notification, when app is in background. For Foreground notification please add your custom logic.

    • This topic was modified 2 years ago by Murali.
    • This topic was modified 2 years ago by Murali.
    • This topic was modified 2 years ago by Murali.
    • This topic was modified 2 years ago by Murali.
    • This topic was modified 2 years ago by Murali.
    • This topic was modified 1 year, 9 months ago by Murali.
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.

Manage push notifications

notification icon
We would like to show you notifications for the latest news and updates.
notification icon
Please wait...processing
notification icon
We would like to show you notifications for the latest news and updates.
notification icon
Please wait...processing
Would you like to install our app?

For IOS and IPAD browsers, Only option to install PWA is to use add to home screen in safari browser

Progressive Web App (PWA) is installed successfully. It will also work in offline