Embed Discourse in a native app?

Our company has native apps for iOS and Android. One of our goals is to bring people back to our apps frequently, and to spend a lot of time in our apps. (The app stores seem to prioritize apps that get a lot of usage.)

We have a pretty solid Discourse forum, but currently we just link out to the forum’s website from the app. iOS users who want to receive forum push notifications then have to download the Discourse app separately. (Android users can receive push notifications directly from the website, which is great, but in that case, they’re still using the website, and not our app.)

We’d like to make the Discourse forum a part of our existing iOS and Android apps, and especially to allow users to receive forum push notifications in our apps, without forcing people to download a separate app or to leave our app to use the forum. (I’m imagining that the implementation would be a web view, much like the Discourse iOS app.)

Is there a way to do something like this today? (I’m guessing not?)

3 Likes

It is possible, but note:

  1. You will have cookie / login problems at the moment, particularly on iOS, due to the way embedded Safari is currently working in iOS 12 and beyond.

  2. You could certainly consume the Discourse API in the native apps to grab Discourse notifications.

A full in-app webview will be more complicated than simply linking out, and implies more developer support for the native apps.

@sam may have other thoughts.

3 Likes

On Android the story is quite simple, spinning up a Chrome Custom Tab is super easy and it shares authentication with Chrome. Only big downside and reason our Android team members avoid using the Android app (and that we are considering killing the Android app) is cause opening a Chrome Tab is slow compared to PWA, so people prefer the PWA.

Being Android though you could possibly automate creating the PWA link and all that Jazz from your app which may be interesting.

On iOS the story is more complex due to Apple bugs.

We have the user API key system @pmusaraj will be working on improving per: Delegated authentication for Discourse Mobile app (which also includes adding documentation)

My recommendation here for you @dfabulich is to hold tight for a month or 2 while we redo our protocol and improve documentation.

8 Likes

How would push notifications work in this story? Would I have to poll? (I’d rather do proper remote pushes.)

I read somewhere that Chrome 72 now support Trusted web activities , which means you can now distribute PWAs in the Google play store. If it works well I think you will have more reason to kill the Android app.

It’s a bit involved, since you need the validation key, paying the Google fee, etc. But it does work.

1 Like

Let me give one good reason not to: some people do not have a Google account and won’t have one. If the app would be distributed over F-Droid, it would be fine, but forcing people into Google is not a friendly move.

1 Like

As long as you ensure that it works with Firefox as well is can also solve

Discourse as an open source application should always prefer open source solutions

Checking back in on this! What’s the story here?

Delegated auth is in, and our new login flow is pretty rock solid on the app. The protocols are all open.

2 Likes

Can you give me a pointer to documentation on this?

1 Like

This is our current spec:

It could certainly use an improvement or 2 so edits on it totally welcome.

Canonical implementation is open source and available at: GitHub - discourse/DiscourseMobile: Discourse Mobile

3 Likes

Very curious where this landed. Has anyone been able to embed discourse into their mobile app via webview and take advantage of notifications?

This happens from time to time, we maintain a handful of white labeled apps for customers.

Unfortunately the cost though of going down this path is enormous. I would say… consider going down this path if you have say a 20k USD a year budget to build/maintain/debug.

2 Likes

I’ve just be working on such a project, but yea the public repo is out of date. If you’d like me to help you you can hire me.

@sam thanks for the words of caution here, as I am just about to embark on this project.

I was encouraged to see the discourse hub seems to already do this - why do you anticipate such a high cost? I was imagining you just need to get the webview and authentication working, then notifications is a nice to have. This would be an awesome feature to add into my already existing app, my team has done webviews previously.

Is there something I am not anticipating that will cause a lot of work / updates?

Historically I have seen how much effort has gone into the trivial web view discourse hub.

On the surface it is “easy” but then you need to worry about 1000 little details.

  • Shrink panel at the bottom
  • The curve on the iPhone
  • Loading spinners
  • Webview constant updates
  • Apple security checks and app approval process
  • Complex debugging … what if something happens on the web view and not the site

This is not even an exhaustive list, I am sure @pmusaraj and @kris.kotlarek can pull out another 20 items.

Apps are very hard to get right and very expensive. These days only strong justification to build one is for iOS and it is not an easy journey.

5 Likes

I originally asked this question because I wanted to retain users in my app, because I think Apple and Google will send free traffic my way.

Is this task any easier (or harder?) in a “Chrome Custom Tab” for Android?

Is it plausible that y’all would offer a library for iOS that wraps a WKWebView and solve this problem for us? (It seems like you’ve already handled 90%+ of the work by implementing Discourse Hub.)

1 Like

I would say Android is “different” hard. Especially since the OS itself is not providing the primitives. Very hard to justify effort there when the PWA is just so good on Android.

We use React Native and components for wrapping WKWebView. The complexity remains sadly. React native updates can also be quite painful to work through from history.

2 Likes

@sam my justification for embarking on this is really around push notifications, and also because I have an existing app that would easily allow my members to do multiple things in the same place (study for their exam, chat in the community, shop, etc.).

But, it sounds like I could have them add the community app as a PWA, and they could get push notifications and updates? Would the PWA have push notifications? Update: found answer here, looks like does not support push notifications.

I’m looking into the PWA option further - perhaps I could even add a link to “Join the Community discussion” into my existing native app, and that would be the correct link to download the PWA?

Thanks!
James