feature-flags-ios
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePostHog feature flags for iOS
适用于iOS的PostHog功能标志
This skill helps you add PostHog feature flags to iOS applications.
本技能可帮助你在iOS应用中添加PostHog功能标志。
Reference files
参考文件
- - Ios feature flags installation - docs
references/ios.md - - Adding feature flag code - docs
references/adding-feature-flag-code.md - - Feature flag best practices - docs
references/best-practices.md
Consult the documentation for API details and framework-specific patterns.
- - iOS功能标志安装文档
references/ios.md - - 添加功能标志代码文档
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 enum with a
PostHogEnvcomputed property that callsvalueandProcessInfo.processInfo.environment[rawValue]s if missing — cases should befatalErrorandprojectToken = "POSTHOG_PROJECT_TOKEN", set in the Xcode scheme's Run environment variableshost = "POSTHOG_HOST" - When adding SPM dependencies to project.pbxproj, create three distinct objects with unique UUIDs — a (with
PBXBuildFile), anproductRef(withXCSwiftPackageProductDependencyandpackage), and anproductName(withXCRemoteSwiftPackageReferenceandrepositoryURL). The build file goes in the Frameworks phaserequirement, the product dependency goes in the target'sfiles, and the package reference goes in the project'spackageProductDependencies.packageReferences - Check the latest release version of posthog-ios at before setting the
https://github.com/PostHog/posthog-ios/releasesin the SPM package reference — do not hardcode a stale versionminimumVersion - If the project uses App Sandbox (macOS), add to the target's build settings so PostHog can reach its servers — do NOT disable the sandbox entirely
ENABLE_OUTGOING_NETWORK_CONNECTIONS = YES
- 通过带有计算属性的
value枚举从环境变量中读取配置,该属性调用PostHogEnv,若缺失则触发ProcessInfo.processInfo.environment[rawValue]——枚举的case应为fatalError和projectToken = "POSTHOG_PROJECT_TOKEN",需在Xcode scheme的Run环境变量中设置host = "POSTHOG_HOST" - 向project.pbxproj添加SPM依赖时,创建三个具有唯一UUID的不同对象:(包含
PBXBuildFile)、productRef(包含XCSwiftPackageProductDependency和package),以及productName(包含XCRemoteSwiftPackageReference和repositoryURL)。构建文件需放入Frameworks阶段的requirement中,产品依赖需放入目标的files中,包引用需放入项目的packageProductDependencies中packageReferences - 在设置SPM包引用的之前,查看
minimumVersion获取posthog-ios的最新版本——不要硬编码过时版本https://github.com/PostHog/posthog-ios/releases - 如果项目使用App Sandbox(macOS),需在目标的构建设置中添加,以便PostHog能够连接到其服务器——切勿完全禁用沙箱
ENABLE_OUTGOING_NETWORK_CONNECTIONS = YES