ערכות ה-SDK האופציונליות של Firebase App Distribution ל-iOS ול-Android SDK מאפשרות להציג התראות בתוך האפליקציה לבודקים, כשיש גרסאות build חדשות של האפליקציה שזמינות להתקנה. במדריך הזה מוסבר איך להשתמש ב-SDK של App Distribution ל-iOS ול-Android כדי ליצור ולהתאים אישית התראות על גרסאות build חדשות לבודקים.
לפני שמתחילים
אם עדיין לא הוספתם את Firebase לפרויקט iOS, אתם צריכים להוסיף אותו.
שלב 1: מפעילים את App Distribution Tester API
בוחרים את הפרויקט במסוף Google Cloud.
בקטע Firebase App Testers API, לוחצים על Enable.
שלב 2: מוסיפים את App Distribution לאפליקציה
פותחים את ה-Podfile שיצרתם לפרויקט (או מריצים את
pod initכדי ליצור אחד), ואז מוסיפים את השורה הבאה בקטע target:pod 'FirebaseAppDistribution'
בספרייה של ה-Podfile, מריצים את הפקודה
pod installופותחים את הקובץ.xcworkspaceשנוצר.מייבאים את המודול של Firebase ב-struct של
Appאו ב-UIApplicationDelegate:Swift
import FirebaseCore import FirebaseAppDistributionObjective-C
@import FirebaseCore; @import FirebaseAppDistribution;מגדירים מופע משותף של
FirebaseAppב-methodapplication(_:didFinishLaunchingWithOptions:)של ה-app delegate:Swift
// Use Firebase library to configure APIs FirebaseApp.configure()Objective-C
// Use Firebase library to configure APIs [FIRApp configure];אם swizzling מושבת, מעבירים את כל כתובות ה-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: הגדרת התראות בתוך האפליקציה
ערכת ה-SDK של App Distribution מספקת שתי דרכים להגדרת התראות על גרסאות build באפליקציה לבודקים: הגדרת התראות בסיסית, שכוללת תיבות דו-שיח מוכנות מראש לעדכון האפליקציה ולכניסה שיוצגו לבודקים, והגדרת התראות מתקדמת, שמאפשרת להתאים אישית את ממשק המשתמש. אם אתם משתמשים ב-SDK של App Distribution בפעם הראשונה, מומלץ להשתמש קודם בהגדרת ההתראה הבסיסית.
הגדרה בסיסית
אפשר להשתמש ב-checkForUpdate כדי להציג תיבת דו-שיח מובנית להפעלת התראות לבודקים שעדיין לא הפעילו התראות, ואז לבדוק אם יש גרסה חדשה. כשמפעילים את ה-method, היא מבצעת את הפעולות הבאות:
בודק אם בודק הפעיל התראות על ידי הצגת בקשה להיכנס אל App Distribution באמצעות חשבון Google שלו.
אם הבודק עדיין לא הפעיל התראות, תוצג תיבת דו-שיח מובנית.
הפעלת ההתראות היא תהליך חד-פעמי במכשיר הבדיקה, והיא נשארת פעילה גם אחרי עדכונים של האפליקציה. ההתראות נשארות פעילות במכשיר הבדיקה עד שמסירים את האפליקציה או עד שמתבצעת קריאה ל-method
signOutTester. מידע נוסף זמין במאמרי העזרה של השיטה (Swift או Objective-C).בודק אם יש גרסאות build חדשות זמינות להתקנה על ידי הבודק.
אפשר להפעיל את checkForUpdate() בכל שלב באפליקציה. לדוגמה, אפשר לבקש מהבודקים להתקין גרסאות build חדשות שזמינות בזמן ההפעלה, על ידי הכללת checkForUpdate() ב-onAppear(perform:) של תצוגת הבסיס (root) של האפליקציה.
בדוגמה הבאה נבדק אם הבודק הפעיל התראות ויש לו גישה ל-build חדש. אם כן, מוצגת תיבת דו-שיח כשה-build זמין להתקנה:
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(), עיינו במאמרי העזרה של App Distribution ל-Swift ול-Objective-C.
שלב 4: פיתוח ובדיקה של ההטמעה
בשלב האחרון, בונים את האפליקציה ובודקים את ההטמעה על ידי הפצת ה-build לבודקים באמצעות מסוף Firebase.
במדריך לפתרון בעיות ב-App Distribution מוסבר איך לפתור בעיות נפוצות, כמו:
- הבודק לא מקבל התראות באפליקציה
- הבודק מתבקש להיכנס לחשבון Google יותר מפעם אחת