跳到主内容
精选85RevenueCat 博客(RSS)产品与增长

用 Apple 端侧模型打造个性化付费墙:完整实操指南

How to create ultra-personalized paywalls with Apple's Foundation Models

原文
推荐理由

给做订阅制 App 的产品和增长团队一套可直接照做的个性化付费墙方案:从收集用户数据、预热模型到写系统指令,含完整代码和提示词模板,今天就能在 iOS 26 上试。

You know personalized paywalls convert better, but what if you could use everything your app already knows about the user to get really (but not inappropriately so) personal?

你知道个性化付费墙转化率更高,但如果你能利用应用已知的用户信息,真正做到(但不过分地)个性化,会怎样?

Timing makes this worth the effort: according to our State of Subscription Apps 2026 report, 55% of 3-day trial cancellations happen on Day 0. The battle for a subscriber is won or lost in the first session, so if your paywall only gets one shot, it should speak to the person looking at it.

时机让这值得一试:根据我们的《2026年订阅应用状况报告》,55%的3天试用取消发生在第0天。订阅用户的争夺在首次会话中就胜负已定,所以如果你的付费墙只有一次机会,它应该对看着它的人说话。

Make sure you're using the correct versions

确保使用正确的版本

Before getting started, make sure your app runs a compatible version of the RevenueCat SDK. Custom variables on the iOS SDK require version 5.57.0. You'll also need to target iOS 26 or above.

开始之前,请确保你的应用运行兼容版本的RevenueCat SDK。iOS SDK上的自定义变量需要5.57.0版本。你还需要将目标系统设为iOS 26或更高。

The example app

示例应用

Chorus, the bird song identifier and walk tracker I'm building for Shipaton 2026, spends its onboarding learning why someone is using the app and what would get them to walk more. It asks about their dream bird, who they go on walks with, when they go on walks, and what would actually get them out the door more.

Chorus,我为Shipaton 2026构建的鸟鸣识别和步行追踪应用,在引导流程中会了解用户为何使用该应用以及什么能促使他们多走路。它会询问他们梦想中的鸟、和谁一起散步、何时散步,以及什么能真正让他们更愿意出门。

This post is about what happens next: using Apple's on-device Foundation Models framework to hand their own ’why’ back to them at the moment of the ask, on a RevenueCat remote paywall. The best part? It's free.

这篇文章讲的是接下来发生的事:使用Apple的端上Foundation Models框架,在RevenueCat远程付费墙上,在用户被询问的那一刻,将他们的‘为什么’反馈给他们。最棒的是?它是免费的。

Here's the basic paywall with no personalization:

这是没有个性化设置的基本付费墙:

Chorus' basic paywall with no personalisation

Chorus的基本付费墙,无个性化

It does the job. It's okay, but it's not really speaking to the user. Let's change that.

它完成了任务。还行,但并没有真正与用户对话。让我们改变这一点。

Custom variables on the paywall

付费墙上的自定义变量

Using RevenueCat remote paywalls, you can start personalizing them using custom variables, but what if you could push that further? What if you could use everything your app already knows about your customer to really get personal?

使用RevenueCat远程付费墙,你可以通过自定义变量开始个性化,但如果你能更进一步呢?如果你能利用应用已知的关于客户的一切信息,真正做到个性化呢?

Open your RevenueCat paywall editor. Click ‘Paywall Logic’ in the left-hand menu and select Variables. Then click ‘Create Variable’ and you'll see the following entry form:

打开你的RevenueCat付费墙编辑器。点击左侧菜单中的‘付费墙逻辑’,选择变量。然后点击‘创建变量’,你会看到以下输入表单:

I'll start by creating the userName variable (possibly the easiest bit of personalization), with the default value ‘Birder’. Chorus asks for the birder's name in onboarding, saves it, and passes it into the remote paywall in Swift like so:

我将首先创建userName变量(可能是最简单的个性化方式),默认值为‘Birder’。Chorus在引导流程中询问观鸟者的名字,保存它,并在Swift中像这样将其传递给远程付费墙:

代码 · 9
struct ChorusPlusPaywall: View {
    let userName: String?   // asked for in onboarding; nil if they skipped it
    var body: some View {
        PaywallView(displayCloseButton: true)
            // If there's no name, send nothing; the dashboard
            // default ("Birder") fills the gap.
            .customPaywallVariables(userName.map { ["userName": .string($0)] } ?? [:])
    }
}
代码 · 9
struct ChorusPlusPaywall: View {
    let userName: String?   // asked for in onboarding; nil if they skipped it
    var body: some View {
        PaywallView(displayCloseButton: true)
            // If there's no name, send nothing; the dashboard
            // default ("Birder") fills the gap.
            .customPaywallVariables(userName.map { ["userName": .string($0)] } ?? [:])
    }
}

That'll produce a paywall like this:

这将产生如下付费墙:

Chorus' paywall using custom variables

Chorus使用自定义变量的付费墙

Better. But we can make it even better with Foundation Models.

好多了。但我们可以用Foundation Models让它变得更好。

Apple's Foundation Models

Apple的Foundation Models

Foundation Models is Apple's on-device large language model (LLM) framework, introduced in iOS 26. It generates text locally, with no server round trip and no per-token cost. Apple says "On-device models excel at a diverse range of text generation tasks, like summarization, entity extraction, text and image understanding, refinement, dialog for games, generating creative content, and more". Perfect for our use case. On-device models are much smaller than cloud-based models, so there are limitations, which I'll go through later.

基础模型是苹果在iOS 26中引入的端侧大语言模型(LLM)框架。它在本地生成文本,无需服务器往返,也没有按令牌计费。苹果表示:“端侧模型擅长处理多种文本生成任务,如摘要、实体提取、文本和图像理解、润色、游戏对话、创意内容生成等”。非常适合我们的用例。端侧模型比云端模型小得多,因此存在一些限制,我稍后会详细说明。

As I mentioned, Chorus gets to know the customer during onboarding — this is where the magic happens.

正如我所提到的,Chorus在用户引导阶段就开始了解客户——这就是魔法发生的地方。

Create a class that handles all interaction with Foundation Models. I've called mine ‘PaywallCopyGenerator’. In Chorus, each onboarding screen is aware of this class, and its functions get called at different points in the flow.

创建一个类来处理与基础模型的所有交互。我将其命名为‘PaywallCopyGenerator’。在Chorus中,每个引导屏幕都了解这个类,并在流程的不同节点调用其函数。

Right at the start, the welcome screen calls prewarm(), which checks SystemLanguageModel.default.availability and warms a session. Devices without Apple Intelligence bail out here: they ship the hand-written fallback line and never touch the model.

在流程开始时,欢迎屏幕调用prewarm(),它会检查SystemLanguageModel.default.availability并预热一个会话。没有Apple Intelligence的设备会在此处退出:它们使用手写的备用文案,并且从不接触模型。

代码 · 6
func prewarm() {
  guard warmSession == nil else { return }
  guard case .available = SystemLanguageModel.default.availability else { return }
  warmSession = LanguageModelSession(instructions: instructions)
  warmSession?.prewarm()
}
代码 · 6
func prewarm() {
  guard warmSession == nil else { return }
  guard case .available = SystemLanguageModel.default.availability else { return }
  warmSession = LanguageModelSession(instructions: instructions)
  warmSession?.prewarm()
}

Prewarming the session reduces the time it takes for the user to see generated output. Do it as early as possible.

预热会话可以减少用户看到生成输出所需的时间。尽早进行预热。

One gotcha: the first time a user's device meets the requirements, SystemLanguageModel can register as unavailable while the OS downloads the model in the background. Don't panic, it resolves itself. In Chorus I don't need to guard with an iOS 26 availability check because the app targets iOS 26; if you support older versions, you will.

一个注意事项:当用户的设备首次满足要求时,SystemLanguageModel可能会在操作系统后台下载模型时注册为不可用。不要惊慌,它会自行解决。在Chorus中,我不需要iOS 26可用性检查,因为应用面向iOS 26;如果你支持旧版本,则需要添加。

Instructions and prompts

指令和提示词

You'll notice you pass system instructions into the session. Apple has great guidance on getting the best out of the model by giving the model a role, persona, and tone. Here are Chorus's system instructions:

你会注意到,你会将会话的系统指令传入。苹果有很好的指导,通过给模型设定角色、人设和语气来充分利用模型。以下是Chorus的系统指令:

代码 · 36
You are a warm British field naturalist writing paywall copy for Chorus, a
bird-walking app. You are given notes about a walker from the app's
onboarding: their dream bird, what would get them out walking more, and how
they walk. Write two short sentences spoken to them as "you".
1. Conjure their next walk as one small imagined moment, built only from
the notes: who is with them, when or where they walk, their dream bird
singing somewhere in it.
2. Say what Chorus can help them do about it.
Never invent people, places, times or history that are not in the notes.
Mention Chorus exactly once, in the help sentence; never name features or
prices. Never the walker's name. No questions, no exclamation marks, no em
dashes. Thirty words at most.
Write like a person talking, not an advert: plain, everyday words, said
simply, nothing you would not say to a friend on a walk. The examples
below are style only; never reuse their scenes, company or times of day
for a different walker. When the notes say who walks with them, hand it
back as theirs: "your partner", "your dog", "your kids", not "a partner"
or "the kids".
Example 1.
Notes: Their dream bird: the goldfinch; they have never heard one; that is
the dream. What would get them out more: knowing new birds were waiting.
They walk at dawn, with their kids. They get out less than they'd like.
Line: Imagine a dawn walk with your kids when a goldfinch strikes up, your
first ever. Chorus can help you catch it the moment it sings.
Example 2.
Notes: Their dream bird: the wren; they hear them all the time and love
them. What would get them out more: keeping the birds they've found close.
They notice birds by ear first.
Line: Picture the next wren that sings before you spot it, one more song
worth keeping. Chorus can help you hold on to every one.
Example 3.
Notes: Their dream bird: the blackbird; they hear them all the time and
love them. What would get them out more: calmer, quieter time outside.
They walk at dusk, as the day's song winds down.
Line: Imagine a quiet walk at dusk, just you and the blackbird seeing the
day out. Chorus can help you make more of those.
代码 · 36
You are a warm British field naturalist writing paywall copy for Chorus, a
bird-walking app. You are given notes about a walker from the app's
onboarding: their dream bird, what would get them out walking more, and how
they walk. Write two short sentences spoken to them as "you".
1. Conjure their next walk as one small imagined moment, built only from
the notes: who is with them, when or where they walk, their dream bird
singing somewhere in it.
2. Say what Chorus can help them do about it.
Never invent people, places, times or history that are not in the notes.
Mention Chorus exactly once, in the help sentence; never name features or
prices. Never the walker's name. No questions, no exclamation marks, no em
dashes. Thirty words at most.
Write like a person talking, not an advert: plain, everyday words, said
simply, nothing you would not say to a friend on a walk. The examples
below are style only; never reuse their scenes, company or times of day
for a different walker. When the notes say who walks with them, hand it
back as theirs: "your partner", "your dog", "your kids", not "a partner"
or "the kids".
Example 1.
Notes: Their dream bird: the goldfinch; they have never heard one; that is
the dream. What would get them out more: knowing new birds were waiting.
They walk at dawn, with their kids. They get out less than they'd like.
Line: Imagine a dawn walk with your kids when a goldfinch strikes up, your
first ever. Chorus can help you catch it the moment it sings.
Example 2.
Notes: Their dream bird: the wren; they hear them all the time and love
them. What would get them out more: keeping the birds they've found close.
They notice birds by ear first.
Line: Picture the next wren that sings before you spot it, one more song
worth keeping. Chorus can help you hold on to every one.
Example 3.
Notes: Their dream bird: the blackbird; they hear them all the time and
love them. What would get them out more: calmer, quieter time outside.
They walk at dusk, as the day's song winds down.
Line: Imagine a quiet walk at dusk, just you and the blackbird seeing the
day out. Chorus can help you make more of those.

The instructions lean on five concepts from Apple's documentation:

这些指令依赖于苹果文档中的五个概念:

  • The persona: Chorus follows Apple's role-playing blueprint. Casting the model as a "warm British field naturalist" with the words "you are" merges character and voice in a single line. The instructions are also written in the exact register they expect back, right down to banning em dashes and obeying that ban themselves.
  • Step-by-step logic: dense task descriptions are broken into a two-step plan. For smaller models, this reduces the cognitive load and keeps sequencing on track.
  • Size constraints: the prompt stays lean. Two paragraphs of imperatives and one clear objective fit Apple's recommended length budget.
  • Few-shot safety: three curated examples establish the style. An "examples are style only" guard prevents exemplar bleed. Without it, the model happily hallucinates dawn walks for night owls.
  • Strategic repetition: high-stakes rules like "never invent" and "exactly once" are reinforced, and the runtime prompt repeats the most important rule last.
  • 人设:Chorus遵循苹果的角色扮演蓝图。将模型设定为“温暖的英国野外博物学家”,并使用“你是”这样的措辞,将角色和声音融合在一行中。指令本身也以期望的回复风格编写,甚至禁止使用破折号,并遵守这一禁令。
  • 逐步逻辑:密集的任务描述被分解为两步计划。对于较小的模型,这减少了认知负担,并保持序列的连贯性。
  • 大小限制:提示词保持精简。两段祈使句和一个明确的目标符合苹果建议的长度预算。
  • 少样本安全:三个精选示例确立风格。一个“示例仅为风格”的防护措施防止示例内容渗漏。若无此防护,模型会愉快地虚构夜猫子的黎明散步。
  • 策略性重复:高风险的规则如“绝不虚构”和“恰好一次”得到强化,运行时提示在最后重复最重要的规则。

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

另一事件,读法相近