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