How to Get Firebase Push User ID in iOS WebView Apps

Surprised young man with smartphone, funny guy holding phone isolated on white background

Firebase Cloud Messaging (FCM) is a popular service used to send push notifications to mobile devices. It’s a powerful tool that can help you engage with your users and keep them informed about important events and updates. In this article, we will explore how to get Firebase Push User ID in Android WebView apps and how it can be done with WebViewGold for iOS by default.

Getting Firebase Push User ID in iOS WebView Apps

To get Firebase Push User ID in iOS WebView apps, you need to use the Firebase Cloud Messaging API. Here are the steps you need to follow:

  1. Add the Firebase SDK to your iOS project
  2. To use Firebase Cloud Messaging in your iOS app, you need to add the Firebase SDK to your project. You can follow the instructions provided by Firebase to add the SDK to your project.
  3. Register your app with Firebase
  4. Once you have added the Firebase SDK to your project, you need to register your app with Firebase. This will allow you to use Firebase Cloud Messaging to send push notifications to your app. You can follow the instructions provided by Firebase to register your app with Firebase.
  5. Get the Firebase Push User ID
  6. Once your app is registered with Firebase, you can get the Firebase Push User ID by calling the FirebaseInstanceId.getInstance().getToken() method. This will return the Firebase Push User ID for the current device.
  7. Send the Firebase Push User ID to your server
  8. Finally, you need to send the Firebase Push User ID to your server so that you can use it to send push notifications to your app. You can use a POST request to send the Firebase Push User ID to your server.

WAIT, there is a shortcut using WebViewGold for iOS!

WebViewGold for iOS is a popular tool used to create WebView apps for iOS devices. With WebViewGold for iOS, you can easily create WebView apps that can access the internet and display web content. WebViewGold also provides a built-in feature to get Firebase Push User ID by default.

If your WebView URL is https://www.example.org, WebViewGold for iOS will call https://www.example.org?firebase_push_id=XYZ instead. Only your first URL request will get that GET variable, so save it in a session or in a cookie to access it on your linked pages.

An alternative or additional way would be to retrieve & process the information on any page via JavaScript:

<script>

window.location.href = “getfirebaseplayerid://”;

alert(firebaseplayerid);

</script>

This script will call the “getfirebaseplayerid” protocol and trigger a callback in your native code. Your native code can then retrieve the Firebase Push User ID and send it back to the WebView using JavaScript.

Conclusion

Firebase Cloud Messaging is a powerful tool that can help you engage with your users and keep them informed about important events and updates. In this article, we explored how to get Firebase Push User ID in iOS WebView apps and how WebViewGold for iOS provides this feature by default. Whether you are building an iOS app, integrating Firebase Cloud Messaging can help you create a more engaging and interactive user experience.