Firebase App Distribution SDK ของ iOS และ Android ที่ไม่บังคับช่วยให้คุณแสดง การแจ้งเตือนในแอปต่อผู้ทดสอบได้เมื่อมีบิลด์ใหม่ของแอปพร้อมให้ ติดตั้ง คำแนะนำนี้จะอธิบายวิธีใช้ App DistributionSDK ของ iOS และ Android เพื่อสร้างและปรับแต่งการแจ้งเตือนบิลด์ใหม่สำหรับผู้ทดสอบ
ก่อนเริ่มต้น
เพิ่ม Firebase ลงในโปรเจ็กต์ iOS หากยังไม่ได้เพิ่ม
ขั้นตอนที่ 1: เปิดใช้ App Distribution Tester API
เลือกโปรเจ็กต์ในคอนโซล Google Cloud
ในส่วน Firebase App Testers API ให้คลิกเปิดใช้
ขั้นตอนที่ 2: เพิ่ม App Distribution ลงในแอป
เปิด Podfile ที่คุณสร้างขึ้นสำหรับโปรเจ็กต์ (หรือเรียกใช้
pod initเพื่อสร้าง) จากนั้นเพิ่มบรรทัดต่อไปนี้ภายในส่วนเป้าหมายpod 'FirebaseAppDistribution'
ในไดเรกทอรีของ Podfile ให้เรียกใช้
pod installจากนั้นเปิดไฟล์.xcworkspaceที่สร้างขึ้นนำเข้าโมดูล Firebase ใน
Appstruct หรือUIApplicationDelegateSwift
import FirebaseCore import FirebaseAppDistributionObjective-C
@import FirebaseCore; @import FirebaseAppDistribution;กำหนดค่า
FirebaseAppอินสแตนซ์ที่แชร์ในเมธอดapplication(_:didFinishLaunchingWithOptions:)ของตัวแทนแอปSwift
// Use Firebase library to configure APIs FirebaseApp.configure()Objective-C
// Use Firebase library to configure APIs [FIRApp configure];หากปิดใช้การสวิซเซิล ให้ส่ง URL ที่เปิดอยู่ไปยัง SDK ของ App Distribution ใน การติดตั้งใช้งาน
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; }สุดท้าย ให้คอมไพล์แอปอีกครั้ง
ขั้นตอนที่ 3: กำหนดค่าการแจ้งเตือนในแอป
App Distribution SDK มี 2 วิธีในการตั้งค่าการแจ้งเตือนการสร้างในแอปสำหรับผู้ทดสอบ ของคุณ ได้แก่ การกำหนดค่าการแจ้งเตือนพื้นฐานซึ่งมาพร้อมกับกล่องโต้ตอบการอัปเดตแอป และการลงชื่อเข้าใช้ที่สร้างไว้ล่วงหน้าเพื่อแสดงต่อผู้ทดสอบ และการกำหนดค่าการแจ้งเตือนขั้นสูง ซึ่งช่วยให้คุณปรับแต่งอินเทอร์เฟซผู้ใช้ของคุณเองได้ เราขอแนะนำให้ใช้การกำหนดค่าการแจ้งเตือนพื้นฐานก่อนหากคุณเพิ่งเริ่มใช้ App Distribution SDK
การกำหนดค่าพื้นฐาน
ใช้ checkForUpdate เพื่อแสดงกล่องโต้ตอบเปิดใช้การแจ้งเตือนที่สร้างไว้ล่วงหน้าต่อผู้ทดสอบที่ยังไม่ได้เปิดใช้การแจ้งเตือน จากนั้นตรวจสอบว่ามีบิลด์ใหม่พร้อมใช้งานหรือไม่ เมื่อเรียกใช้ เมธอดจะดำเนินการตามลำดับต่อไปนี้
ตรวจสอบว่าผู้ทดสอบได้เปิดใช้การแจ้งเตือนหรือไม่โดยแจ้งให้ผู้ทดสอบลงชื่อเข้าใช้ App Distribution ด้วยบัญชี Google
หากผู้ทดสอบยังไม่ได้เปิดใช้การแจ้งเตือน ระบบจะแสดงกล่องโต้ตอบที่สร้างไว้ล่วงหน้า
การเปิดใช้การแจ้งเตือนเป็นกระบวนการแบบครั้งเดียวในอุปกรณ์ทดสอบและจะยังคงอยู่เมื่อมีการอัปเดตแอป การแจ้งเตือนจะยังคงเปิดใช้ในอุปกรณ์ทดสอบจนกว่าจะมีการถอนการติดตั้งแอปหรือจนกว่าจะมีการเรียกใช้เมธอด
signOutTesterดูข้อมูลเพิ่มเติมได้ในเอกสารอ้างอิงของเมธอด (Swift หรือ Objective-C)ตรวจสอบบิลด์ใหม่ที่พร้อมให้ผู้ทดสอบติดตั้ง
คุณเรียกใช้ checkForUpdate() ได้ทุกเมื่อในแอป เช่น คุณ
สามารถแจ้งให้ผู้ทดสอบติดตั้งบิลด์ที่เพิ่งพร้อมใช้งานเมื่อเริ่มต้นได้โดย
ใส่ checkForUpdate() ใน onAppear(perform:) ของมุมมองรากของแอป
ตัวอย่างต่อไปนี้จะตรวจสอบว่าผู้ทดสอบได้เปิดใช้การแจ้งเตือน และมีสิทธิ์เข้าถึงบิลด์ใหม่หรือไม่ หากมีสิทธิ์ ระบบจะแสดงกล่องโต้ตอบเมื่อ บิลด์พร้อมให้ติดตั้ง
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 บัญชีผู้ทดสอบแล้วหรือไม่ เพื่อให้คุณเลือกแสดง UI การลงชื่อเข้าใช้
เฉพาะผู้ทดสอบที่ยังไม่ได้ลงชื่อเข้าใช้ หลังจากผู้ทดสอบ
ลงชื่อเข้าใช้แล้ว คุณจะเรียกใช้ 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() ได้ในเอกสารอ้างอิงสำหรับ App Distribution
Swift
และ Objective-C
ขั้นตอนที่ 4: สร้างและทดสอบการติดตั้งใช้งาน
สุดท้าย ให้สร้างแอปและทดสอบการติดตั้งใช้งานโดยแจกจ่ายบิลด์ ให้ผู้ทดสอบโดยใช้ Firebase Console
ไปที่App Distributionคู่มือการแก้ปัญหา เพื่อรับความช่วยเหลือเกี่ยวกับปัญหาที่พบบ่อย เช่น
- ผู้ทดสอบไม่ได้รับการแจ้งเตือนในแอป
 - ระบบแจ้งให้ผู้ทดสอบลงชื่อเข้าใช้ Google มากกว่า 1 ครั้ง