您也可以選擇使用 iOS 和 Android SDK,在應用程式有新版本可供安裝時,向測試人員顯示應用程式內快訊。Firebase App Distribution本指南說明如何使用 App Distribution iOS 和 Android SDK,為測試人員建立及自訂新版建構作業的快訊。
事前準備
如果您尚未將 Firebase 新增至 iOS 專案,請先新增。
步驟 1:啟用 App Distribution 測試人員 API
- 在 Google Cloud 控制台中選取專案。 
- 在「Firebase App Testers API」下方,按一下「啟用」。 
步驟 2:在應用程式中加入 App Distribution
- 開啟為專案建立的 Podfile (或執行 - pod init建立 Podfile),然後在目標區段中加入下列程式碼行:- pod 'FirebaseAppDistribution' 
- 在 Podfile 目錄中執行 - pod install,然後開啟建立的- .xcworkspace檔案。
- 在 - App結構體或- UIApplicationDelegate中匯入 Firebase 模組:- Swift- import FirebaseCore import FirebaseAppDistribution- Objective-C- @import FirebaseCore; @import FirebaseAppDistribution;
- 在應用程式委派的 - application(_:didFinishLaunchingWithOptions:)方法中,設定- FirebaseApp共用例項:- Swift- // Use Firebase library to configure APIs FirebaseApp.configure()- Objective-C- // Use Firebase library to configure APIs [FIRApp configure];
- 如果停用 Swizzling,請在 - application(_:open:options:)的實作中,將所有開啟的網址傳遞至 App Distribution SDK:- Swift- 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 }- Objective-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 向尚未啟用快訊的測試人員顯示預先建構的啟用快訊對話方塊,然後檢查是否有新版本。呼叫時,這個方法會執行下列序列:
- 提示測試人員登入 App Distribution Google 帳戶,檢查他們是否已啟用快訊。 
- 如果測試人員尚未啟用警示,則會顯示預先建構的對話方塊。 - 在測試裝置上啟用快訊後,即使應用程式更新,快訊也會持續啟用。除非解除安裝應用程式或呼叫 - signOutTester方法,否則測試裝置上的快訊會保持啟用狀態。詳情請參閱方法參考說明文件 (Swift 或 Objective-C)。
- 檢查是否有可供測試人員安裝的新建構版本。 
您可以在應用程式中的任何時間點叫用 checkForUpdate()。舉例來說,您可以在應用程式根檢視區塊的 onAppear(perform:) 中加入 checkForUpdate(),在啟動時提示測試人員安裝新推出的建構版本。
以下範例會檢查測試人員是否已啟用快訊並可存取新版本,如果符合條件,則會在可安裝版本時顯示對話方塊:
Swift
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)
})
Objective-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測試人員帳戶,因此您可以選擇只向尚未登入的測試人員顯示登入使用者介面。測試人員登入後,您就可以呼叫 checkForUpdate(),檢查測試人員是否能存取新版本。
Swift
// 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
  })
}
Objective-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疑難排解指南,例如:
- 測試人員未收到應用程式內警示
- 系統多次提示測試人員登入 Google 帳戶