可选的 Firebase App Distribution iOS 和 Android SDK 让您可以在您的应用程序的新版本可供安装时向您的测试人员显示应用程序内警报。本指南介绍了如何使用 App Distribution iOS 和 Android SDK 为您的测试人员创建和自定义新的构建警报。
在你开始之前
如果您还没有,请将 Firebase 添加到您的 iOS 项目中。
第 1 步:启用 App Distribution Tester API
在Google Cloud Console中选择您的项目。
在Firebase App Testers API下,单击启用。
第 2 步:将 App Distribution 添加到您的应用
打开您为项目创建的 Podfile(或运行
pod init
创建一个),然后在目标部分中添加以下行:pod 'FirebaseAppDistribution'
在 podfile 的目录中,运行
pod install
,然后打开创建的.xcworkspace
文件。在您的
App
结构或UIApplicationDelegate
中导入 Firebase 模块:迅速
import FirebaseCore import FirebaseAppDistribution
目标-C
@import FirebaseCore; @import FirebaseAppDistribution;
在您的应用委托的
application(_:didFinishLaunchingWithOptions:)
方法中配置一个FirebaseApp
共享实例:迅速
// Use Firebase library to configure APIs FirebaseApp.configure()
目标-C
// Use Firebase library to configure APIs [FIRApp configure];
如果 swizzling 被禁用,请在您的
application(_:open:options:)
实现中将任何打开的 URL 传递给 App Distribution SDK:迅速
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { if AppDistribution.appDistribution().application(application, open: url, options: options) { return true } // Handle other non-Firebase URLs here. return false }
目标-C
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options { if ([[FIRAppDistribution appDistribution] application:app openURL:url options:options]) { return YES; } // Handle other non-Firebase URLs here. return NO; }
最后,重新编译您的应用程序。
第 3 步:配置应用内提醒
App Distribution SDK 提供了两种为测试人员设置应用程序内构建警报的方法:一种是基本警报配置,其中包含预构建的应用程序更新和登录对话框以显示给测试人员,另一种是高级警报配置,它允许您可以自定义您自己的用户界面。如果您不熟悉 App Distribution SDK,我们建议您首先使用基本警报配置。
基本配置
使用checkForUpdate
向尚未启用警报的测试人员显示预构建的启用警报对话框,然后检查是否有新版本可用。调用时,该方法执行以下序列:
通过提示测试人员使用其 Google 帐户登录 App Distribution 来检查测试人员是否已启用警报。
如果测试人员尚未启用警报,则显示预建对话。
启用警报是测试设备上的一次性过程,并且在您的应用程序更新期间持续存在。在卸载应用程序或调用
signOutTester
方法之前,警报在测试设备上保持启用状态。有关详细信息,请参阅方法的参考文档( Swift或Objective-C )。检查新的可用构建以供测试人员安装。
您可以在应用程序的任何位置调用checkForUpdate()
。例如,您可以通过在应用根视图的onAppear(perform:)
中包含checkForUpdate()
来提示您的测试人员在启动时安装新的可用构建。
以下示例检查测试人员是否已启用警报并有权访问新构建,如果是,则在构建可用于安装时显示对话框:
迅速
AppDistribution.appDistribution().checkForUpdate(completion: { release, error in
if error != nil {
// Handle error
return
}
guard let release = release else {
return
}
// Customize your alerts here.
let title = "New Version Available"
let message = "Version \(release.displayVersion)(\(release.buildVersion)) is available."
let uialert = UIAlertController(title: title,message: message, preferredStyle: .alert)
uialert.addAction(UIAlertAction(title: "Update", style: UIAlertAction.Style.default) {
_ in
UIApplication.shared.open(release.downloadURL)
})
uialert.addAction(UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel) {
_ in
})
// self should be a UIViewController.
self.present(uialert, animated: true, completion: nil)
})
目标-C
[[FIRAppDistribution appDistribution]
checkForUpdateWithCompletion:^(FIRAppDistributionRelease *_Nullable release,
NSError *_Nullable error) {
if (error) {
// Handle error
return;
}
if (release) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"New Version Available"
message:[NSString stringWithFormat:@"Version %@ (%@) is available.", release.displayVersion,
release.buildVersion] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *updateAction = [UIAlertAction actionWithTitle:@"Update"
style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[[UIApplication sharedApplication] openURL:release.downloadURL options:@{}
completionHandler:nil];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {}];
[alert addAction:updateAction];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:nil];
}
}];
高级配置
方法signInTester()
和isTesterSignedIn
使您可以更灵活地自定义测试人员的登录体验,因此它可以更好地匹配您的应用程序的外观。
以下示例检查测试人员是否已登录其 Firebase App Distribution 测试人员帐户,因此您可以选择仅对尚未登录的测试人员显示您的登录 UI。测试人员登录后,您可以随后调用checkForUpdate()
检查测试人员是否有权访问新构建。
迅速
// Sign in a tester without automatically checking for update
if (!AppDistribution.appDistribution().isTesterSignedIn) {
AppDistribution.appDistribution().signInTester (completion: { error in
// completion block for signInTester
if (error != nil) {
// handle failed sign in
return
}
// handle successful sign in
})
}
// Only check for update if tester is already signed in - do not prompt
if (AppDistribution.appDistribution().isTesterSignedIn) {
AppDistribution.appDistribution().checkForUpdate(completion: { release, error in
// completion block for check for update
})
}
目标-C
// Sign in a tester without automatically checking for update
if(![[FIRAppDistribution appDistribution] isTesterSignedIn]) {
[[FIRAppDistribution appDistribution]
signInTesterWithCompletion:^(NSError *_Nullable error) {
// completion block for signInTester
if (error) {
// handle failed sign in
return;
}
// handle successful sign in
}];
}
// only check for update if tester is already signed in - do not prompt
if([[FIRAppDistribution appDistribution] isTesterSignedIn]) {
[[FIRAppDistribution appDistribution]
checkForUpdateWithCompletion:^(FIRAppDistributionRelease *_Nullable release,
NSError *_Nullable error) {
// completion block for check for update
}];
}
有关其他方法(包括signOutTester()
的信息,请参阅Swift和Objective-C的 App Distribution 参考文档。
第 4 步:构建和测试您的实施
最后,构建您的应用程序并通过使用 Firebase 控制台将构建分发给测试人员来测试您的实施。
请访问App Distribution Troubleshooting 指南以获取有关常见问题的帮助,例如:
- 测试人员未收到应用内提醒
- 系统多次提示测试人员登录 Google