初始化项目
1, 安装Cocopods依赖
bash
cd ios
pod install
2,设置最低支持iOS版本,我这里最低支持的设备是iphone6s,系统是iOS13
Podfile 设置 platform :ios, '13.0'
3, 设置Marketing Version 为 ${FLUTTER_BUILD_NAME}
4, 设置Current Project Version 为 ${FLUTTER_BUILD_NUMBER}
5, 查看Xcode面板中的Version/Build 已经和FLUTTER_BUILD_NAME/FLUTTER_BUILD_NUMBER 同步
c
FLUTTER_BUILD_NAME=1.0.1
FLUTTER_BUILD_NUMBER=3
2, 创建 PROJECT Configurations
依次 Duplicate "Debug/Release/Profile" Configuration, 并在每种编译模式下增加三种不同环境的后缀,例如: Debug-dev/Debug-qa/Debug-product , 注意:不能写错,否则运行会报错
3,创建不同环境 xcconfig
由于 iOS没有 productFlavors,如果我们需要实现不同环境配置不同参数。 这里有两种方式:
1, 直接修改不同Configurations里面的值
但这样不利于统一管理,因此我们使用第二种方式
2,通过 xcconfig 文件管理不同环境的变量配置
c
[Debug-dev.xcconfig]
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Flutter/Generated.xcconfig"
/// App name
PRODUCT_NAME=Pollka Snow Dev
/// App identifier
PRODUCT_BUNDLE_IDENTIFIER=com.ski.pollka.snow.dev
/// FLUTTER_TARGET
FLUTTER_TARGET=lib/main_dev.dart
// Custom
ENV=dev
[Debug-qa.xcconfig]
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Flutter/Generated.xcconfig"
/// App name
PRODUCT_NAME=Pollka Snow Test
/// App identifier
PRODUCT_BUNDLE_IDENTIFIER=com.ski.pollka.snow.qa
/// FLUTTER_TARGET
FLUTTER_TARGET=lib/main_qa.dart
// Custom
ENV=qa
[Debug-product.xcconfig]
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Flutter/Generated.xcconfig"
/// App name
PRODUCT_NAME=Pollka Snow
/// App identifier
PRODUCT_BUNDLE_IDENTIFIER=com.ski.pollka.snow
/// FLUTTER_TARGET
FLUTTER_TARGET=lib/main_product.dart
// Custom
ENV=product
Release-dev.xcconfig 只需要导入 Debug-dev.xcconfig
arduino
[Release-dev.xcconfig]
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Flutter/Generated.xcconfig"
#include "Debug-dev.xcconfig"
4,创建不同环境Scheme
1,选中 Runner,依次创建 dev/qa/product Scheme, 创建完成可以删除 Runner Scheme
2,创建完成的效果如下,然后点击 Edit Scheme
3,依次配置 dev/qa/product Scheme 中的各种 Build Configuration
4,设置 Bundle Display Name/Product Name 为 $(PRODUCT_NAME)
App 名字:
IPA文件名字
5,设置Product Bundle Identifier
6,检查FLUTTER_TARGET/ENV