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 个赞

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 个赞

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 个赞

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 个赞

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.

2 个赞

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 个赞

Can you give me a pointer to documentation on this?

1 个赞

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 个赞

非常想知道这个最终效果如何。有人能够通过 webview 将 Discourse 嵌入到他们的移动应用程序中并利用通知吗?

这种情况时有发生,我们为客户维护着一些白标应用程序。

不幸的是,走这条路的成本非常高。我想说……如果你每年有大约 2 万美元的预算用于构建/维护/调试,可以考虑走这条路。

2 个赞

我刚完成了一个这样的项目,但是的,公共存储库已过时。如果您希望我提供帮助,可以聘请我。

@sam 感谢您的提醒,我正要开始这个项目。

我很高兴地看到 discourse hub 似乎已经实现了这一点——为什么您预计成本会如此之高?我设想您只需要实现 webview 和身份验证,然后通知功能只是一个锦上添花的功能。这将是我现有应用程序的一个很棒的功能,我的团队以前做过 webview。

是不是有什么我没有预料到的事情会导致大量的工作/更新?

历史上,我曾见过在微不足道的 Web 视图 Discourse Hub 上付出了多少努力。

表面上它“很简单”,但随后你需要担心 1000 个细节。

  • 收缩底部的面板
  • iPhone 上的曲线
  • 加载微调器
  • Web 视图的持续更新
  • Apple 安全检查和应用程序审批流程
  • 复杂的调试……如果 Web 视图上发生某些事情而网站上没有呢?

这甚至不是一个详尽的列表,我相信 @pmusaraj@kris.kotlarek 可以再列出 20 项。

应用程序很难做好,而且成本很高。如今,只有强有力的理由才能构建一个,那就是针对 iOS,而且这并非易事。

5 个赞

我最初问这个问题是因为我想留住应用中的用户,因为我认为苹果和谷歌会为我带来免费流量。

在 Android 的“Chrome 自定义标签页”中,这项任务是否更容易(或更难)?

你们是否有可能为 iOS 提供一个包装了 WKWebView 的库来为我们解决这个问题?(通过实现 Discourse Hub,你们似乎已经完成了 90% 以上的工作。)

1 个赞

我会说 Android 的难度是“不同”的。特别是当操作系统本身不提供原始功能时。当 PWA 在 Android 上表现如此出色时,很难证明在那里付出的努力是合理的。

我们使用 React Native 和组件来包装 WKWebView。复杂度依然存在,令人遗憾。从过去的经验来看,React Native 的更新也可能非常痛苦。

2 个赞

@sam 我之所以着手做这件事,主要是因为推送通知,而且我有一个现有的应用程序,可以轻松地让我的会员在同一个地方做多件事情(备考、在社区聊天、购物等)。

但是,听起来我可以在 PWA 中添加社区应用程序,并且他们可以收到推送通知和更新?PWA 会有推送通知吗?更新:在这里找到了答案,看起来不支持推送通知。

我正在进一步研究 PWA 选项 - 也许我甚至可以在我现有的原生应用程序中添加一个链接“加入社区讨论”,这将是下载 PWA 的正确链接?

谢谢!
James