通知測試人員新版本

選用 Firebase 應用程式發布的 iOS 和 Android SDK 在您的應用程式有新版本可供下載時,向測試人員傳送應用程式內快訊 安裝。本指南說明如何使用 iOS 和 Android SDK 建立及自訂新的版本快訊給測試人員。

事前準備

如果您尚未將 Firebase 新增至 iOS 專案,請先完成這項操作。

步驟 1:啟用 App Distribution Tester API

  1. 請在 Google Cloud 控制台

  2. 按一下「Firebase App Testers API」下方的「啟用」

步驟 2:在應用程式中新增應用程式發布內容

  1. 開啟您為專案建立的 Podfile (或執行 pod init 來建立專案) one),然後在目標區段中新增下列程式碼:

    pod 'FirebaseAppDistribution'
  2. 在 Podfile 目錄中執行 pod install,然後開啟 已建立 .xcworkspace 個檔案。

  3. 將 Firebase 模組匯入 App 結構或 UIApplicationDelegate

    Swift

    import FirebaseCore
    import FirebaseAppDistribution
    

    Objective-C

    @import FirebaseCore;
    @import FirebaseAppDistribution;
    
  4. 在應用程式委派項目中設定 FirebaseApp 共用例項 application(_:didFinishLaunchingWithOptions:) 方法:

    Swift

    // Use Firebase library to configure APIs
    FirebaseApp.configure()
    

    Objective-C

    // Use Firebase library to configure APIs
    [FIRApp configure];
    
  5. 如果停用檢查功能,請將所有開啟的網址傳遞至 App Distribution SDK 實作 application(_:open:options:) 的方式:

    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;
    }
    
  6. 最後,重新編譯應用程式。

步驟 3:設定應用程式內快訊

應用程式發布 SDK 提供兩種設定應用程式內建構快訊的方式: 您的測試人員:這是基本的快訊設定,隨附預先建構的應用程式更新 和登入對話方塊 (向測試人員顯示) 以及進階快訊 即可自訂使用者介面。三 建議您先使用基本快訊設定 應用程式發布 SDK。

基本設定

使用 checkForUpdate 顯示預先建立的啟用快訊對話方塊, 再檢查新版本 廣告。呼叫此方法時,會執行以下序列:

  1. 提示測試人員登入帳戶,檢查是否已啟用快訊功能 透過 Google 帳戶發布應用程式。

  2. 如果測試人員尚未啟用快訊,系統會顯示預先建構的對話方塊。

    快訊功能在測試裝置上只需啟用一次,將持續到 應用程式的更新測試裝置上的快訊會保持啟用狀態,直到 解除安裝應用程式,或直到呼叫 signOutTester 方法為止。 請參閱該方法的參考說明文件 (SwiftObjective-C) 瞭解詳情

  3. 檢查可供測試人員安裝的新版本。

您隨時可以在應用程式中叫用 checkForUpdate()。舉例來說, 可讓測試人員在啟動時安裝新可用的版本,方法是 在應用程式根目錄的 onAppear(perform:) 中加入 checkForUpdate() 檢視畫面。

下列範例會檢查測試人員是否已啟用快訊 且可存取新建構作業,如果是的話,會在觸發 可用的版本:

Swift

注意:這項產品不適用於 macOS、Mac Catalyst、tvOS 或 watchOS 目標。
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

注意:這項產品不適用於 macOS、Mac Catalyst、tvOS 或 watchOS 目標。
[[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 應用程式發布測試人員帳戶,可讓你在資訊主頁上顯示 登入使用者介面。測試人員 登入後,您就能呼叫 checkForUpdate() 檢查測試人員是否已 取得新建構作業的存取權

Swift

注意:這項產品不適用於 macOS、Mac Catalyst、tvOS 或 watchOS 目標。
// 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

注意:這項產品不適用於 macOS、Mac Catalyst、tvOS 或 watchOS 目標。
// 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(), 請參閱 SwiftObjective-C

步驟 4:建構並測試實作成果

最後,請建構應用程式並測試導入作業,方法是 在 Android Vitals 中 提供給測試人員

請造訪 應用程式發布疑難排解指南 以取得常見問題的說明,例如:

  • 測試人員沒有收到應用程式內快訊
  • 系統多次提示測試人員登入 Google