feature-flags-ios

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PostHog feature flags for iOS

适用于iOS的PostHog功能标志

This skill helps you add PostHog feature flags to iOS applications.
本技能可帮助你在iOS应用中添加PostHog功能标志。

Reference files

参考文件

  • references/ios.md
    - Ios feature flags installation - docs
  • references/adding-feature-flag-code.md
    - Adding feature flag code - docs
  • references/best-practices.md
    - Feature flag best practices - docs
Consult the documentation for API details and framework-specific patterns.
  • references/ios.md
    - iOS功能标志安装文档
  • references/adding-feature-flag-code.md
    - 添加功能标志代码文档
  • references/best-practices.md
    - 功能标志最佳实践文档
如需了解API详情和特定框架的模式,请查阅相关文档。

Key principles

核心原则

  • Environment variables: Always use environment variables for PostHog keys. Never hardcode them.
  • Minimal changes: Add feature flag code alongside existing logic. Don't replace or restructure existing code.
  • Boolean flags first: Default to boolean flag checks unless the user specifically asks for multivariate flags.
  • Server-side when possible: Prefer server-side flag evaluation to avoid UI flicker.
  • 环境变量:始终使用环境变量存储PostHog密钥,切勿硬编码。
  • 最小改动:在现有逻辑旁添加功能标志代码,不要替换或重构现有代码。
  • 优先布尔型标志:默认使用布尔型标志检查,除非用户明确要求多变量标志。
  • 尽可能使用服务端评估:优先选择服务端标志评估,以避免UI闪烁。

PostHog MCP tools

PostHog MCP工具

Check if a PostHog MCP server is connected. If available, look for tools related to feature flag management (creating, listing, updating, deleting flags). Use these tools to manage flags directly in PostHog rather than requiring the user to do it manually in the dashboard.
检查是否已连接PostHog MCP服务器。如果已连接,查找与功能标志管理相关的工具(创建、列出、更新、删除标志)。使用这些工具直接在PostHog中管理标志,无需用户在仪表板中手动操作。

Framework guidelines

框架指南

  • Read configuration from environment variables via a
    PostHogEnv
    enum with a
    value
    computed property that calls
    ProcessInfo.processInfo.environment[rawValue]
    and
    fatalError
    s if missing — cases should be
    projectToken = "POSTHOG_PROJECT_TOKEN"
    and
    host = "POSTHOG_HOST"
    , set in the Xcode scheme's Run environment variables
  • When adding SPM dependencies to project.pbxproj, create three distinct objects with unique UUIDs — a
    PBXBuildFile
    (with
    productRef
    ), an
    XCSwiftPackageProductDependency
    (with
    package
    and
    productName
    ), and an
    XCRemoteSwiftPackageReference
    (with
    repositoryURL
    and
    requirement
    ). The build file goes in the Frameworks phase
    files
    , the product dependency goes in the target's
    packageProductDependencies
    , and the package reference goes in the project's
    packageReferences
    .
  • Check the latest release version of posthog-ios at
    https://github.com/PostHog/posthog-ios/releases
    before setting the
    minimumVersion
    in the SPM package reference — do not hardcode a stale version
  • If the project uses App Sandbox (macOS), add
    ENABLE_OUTGOING_NETWORK_CONNECTIONS = YES
    to the target's build settings so PostHog can reach its servers — do NOT disable the sandbox entirely
  • 通过带有
    value
    计算属性的
    PostHogEnv
    枚举从环境变量中读取配置,该属性调用
    ProcessInfo.processInfo.environment[rawValue]
    ,若缺失则触发
    fatalError
    ——枚举的case应为
    projectToken = "POSTHOG_PROJECT_TOKEN"
    host = "POSTHOG_HOST"
    ,需在Xcode scheme的Run环境变量中设置
  • 向project.pbxproj添加SPM依赖时,创建三个具有唯一UUID的不同对象:
    PBXBuildFile
    (包含
    productRef
    )、
    XCSwiftPackageProductDependency
    (包含
    package
    productName
    ),以及
    XCRemoteSwiftPackageReference
    (包含
    repositoryURL
    requirement
    )。构建文件需放入Frameworks阶段的
    files
    中,产品依赖需放入目标的
    packageProductDependencies
    中,包引用需放入项目的
    packageReferences
  • 在设置SPM包引用的
    minimumVersion
    之前,查看
    https://github.com/PostHog/posthog-ios/releases
    获取posthog-ios的最新版本——不要硬编码过时版本
  • 如果项目使用App Sandbox(macOS),需在目标的构建设置中添加
    ENABLE_OUTGOING_NETWORK_CONNECTIONS = YES
    ,以便PostHog能够连接到其服务器——切勿完全禁用沙箱