ตัวเลือก 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 : เพิ่มการแจกจ่ายแอปไปยังแอปของคุณ
เปิด Podfile ที่คุณสร้างขึ้นสำหรับโครงการ (หรือเรียกใช้
pod init
เพื่อสร้าง) จากนั้นเพิ่มบรรทัดต่อไปนี้ในส่วนเป้าหมาย:pod 'FirebaseAppDistribution'
ในไดเร็กทอรีของ podfile ของคุณ ให้รัน
pod install
จากนั้นเปิดไฟล์ ..xcworkspace
ที่สร้างขึ้นเข้ารหัส ID แอป Google ของคุณ ( จำเป็นสำหรับ iOS เวอร์ชัน 9 และ 10 เท่านั้น ):
เข้ารหัส ID แอป Google ของคุณ
เพิ่มรูปแบบ
appdistribution-<encoded-google-app-id>
โดยการรวมข้อมูลโค้ดในInfo.plist file
ของคุณ (โปรดดู เอกสารประกอบของ Apple สำหรับคำแนะนำในการเพิ่มรูปแบบ URL ใน Xcode):<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLSchemes</key> <array> <string>appdistribution-<encoded-google-app-id></string> </array> </dict> </array>
จากนั้น เข้ารหัส ID แอป Google ของคุณโดยแทนที่เครื่องหมายทวิภาค (:) ด้วยขีดกลาง (-) โปรดทราบว่า ID แอป Google ของคุณจะอยู่ในไฟล์
GoogleService-Info.plist
ตัวอย่างเช่น หากรหัสแอป Google ของคุณคือ:7:77777777777:ios:123456789
รหัสแอป Google ที่เข้ารหัสของคุณคือ:
7-77777777777-ios-123456789
นำเข้าโมดูล Firebase ใน
App
struct หรือUIApplicationDelegate
ของคุณ:Swift
import FirebaseCore
วัตถุประสงค์-C
@import FirebaseCore;
กำหนดค่าอินสแตนซ์ที่ใช้ร่วมกันของ
FirebaseApp
โดยทั่วไปในเครื่องมือเริ่มต้นของApp
ปหรือวิธีการของapplication(_:didFinishLaunchingWithOptions:)
ของแอปหรือผู้รับมอบสิทธิ์แอป:Swift
// Use Firebase library to configure APIs FirebaseApp.configure()
วัตถุประสงค์-C
// Use Firebase library to configure APIs [FIRApp configure];
สุดท้าย คอมไพล์แอปของคุณใหม่
ขั้นตอนที่ 3 : กำหนดค่าการแจ้งเตือนในแอป
App Distribution SDK มีสองวิธีในการตั้งค่าการแจ้งเตือนบิวด์ในแอปสำหรับผู้ทดสอบของคุณ: การกำหนดค่าการแจ้งเตือนพื้นฐาน ซึ่งมาพร้อมกับการอัปเดตแอปที่สร้างไว้ล่วงหน้าและกล่องโต้ตอบการลงชื่อเข้าใช้เพื่อแสดงให้ผู้ทดสอบทราบ และการกำหนดค่าการแจ้งเตือนขั้นสูง ซึ่งช่วยให้ คุณปรับแต่งส่วนต่อประสานผู้ใช้ของคุณเอง เราขอแนะนำให้คุณใช้การกำหนดค่าการแจ้งเตือนพื้นฐานก่อน หากคุณเพิ่งเริ่มใช้ 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)
})
วัตถุประสงค์-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
})
}
วัตถุประสงค์-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
ไปที่ คู่มือการแก้ไขปัญหาการแจกจ่ายแอป สำหรับความช่วยเหลือเกี่ยวกับปัญหาทั่วไป เช่น:
- ผู้ทดสอบไม่ได้รับการแจ้งเตือนในแอป
- ผู้ทดสอบได้รับแจ้งให้ลงชื่อเข้าใช้ Google มากกว่าหนึ่งครั้ง