שליחת הודעה לבודקים על גרסאות build חדשות


Firebase App Distribution iOS ו-Android SDKs האופציונליים מאפשרים להציג התראות בתוך האפליקציה לבודקים כשגרסאות חדשות של האפליקציה זמינות להתקנה. במדריך הזה מוסבר איך להשתמש בערכות ה-SDK של App Distribution iOS ו-Android כדי ליצור ולהתאים אישית התראות חדשות על גרסאות build לבוחנים.

לפני שמתחילים

אם עדיין לא עשיתם זאת, מוסיפים את Firebase לפרויקט iOS.

שלב 1: מפעילים את App Distribution Tester API

  1. בוחרים את הפרויקט במסוף Google Cloud.

  2. בקטע Firebase App Testers API, לוחצים על Enable (הפעלה).

שלב 2: מוסיפים את App Distribution לאפליקציה

  1. פותחים את ה-Podfile שיצרתם עבור הפרויקט (או מריצים את הפקודה pod init כדי ליצור אחד), ואז מוסיפים את השורה הבאה בתוך קטע היעד:

    pod 'FirebaseAppDistribution'
  2. בספרייה של קובץ ה-podfile, מריצים את הפקודה pod install ואז פותחים את הקובץ .xcworkspace שנוצר.

  3. מייבאים את מודול Firebase אל App struct או אל 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. אם השבתתם את ה-swizzling, צריך להעביר את כל כתובות ה-URL שנפתחו אל 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: הגדרת התראות בתוך האפליקציה

App Distribution SDK מספק שתי דרכים להגדרת התראות על גרסאות build באפליקציה עבור הבודקים: הגדרת התראות בסיסית, שכוללת דיאלוגים מוכנים מראש של עדכון אפליקציה וכניסה שמוצגים לבודקים, והגדרת התראות מתקדמת, שמאפשרת לכם להתאים אישית את ממשק המשתמש. אם אתם חדשים בשימוש ב-App Distribution SDK, מומלץ להשתמש קודם בהגדרת ההתראות הבסיסית.

הגדרה בסיסית

משתמשים ב-checkForUpdate כדי להציג תיבת דו-שיח מוכנה מראש להפעלת התראות לבודקים שעדיין לא הפעילו התראות, ואז בודקים אם יש גרסה חדשה. כשמפעילים את ה-method, מתבצעת הרצף הבא:

  1. בודק אם בודק הפעיל התראות על ידי בקשה ממנו להיכנס ל-App Distribution באמצעות חשבון Google.

  2. אם הבודק עדיין לא הפעיל את ההתראות, מוצג לו דו-שיח מוכן מראש.

    הפעלת ההתראות היא תהליך חד-פעמי במכשיר הבדיקה, והן ימשיכו לפעול גם אחרי עדכונים של האפליקציה. ההתראות ימשיכו לפעול במכשיר הבדיקה עד להסרת האפליקציה או עד לקריאה לשיטה signOutTester. מידע נוסף מופיע במאמרי העזרה של השיטה (Swift או Objective-C).

  3. בודקת אם יש גרסאות חדשות שזמינות להתקנה על ידי הבודק.

אפשר להפעיל את checkForUpdate() בכל שלב באפליקציה. לדוגמה, אפשר להציג לבודקים הודעה להתקין גרסאות חדשות שזמינות בהפעלה, על ידי הכללת checkForUpdate() ב-onAppear(perform:) של תצוגת הבסיס של האפליקציה.

בדוגמה הבאה נבדק אם הבודק הפעיל התראות ויש לו גישה לגרסת build חדשה. אם כן, מוצג דו-שיח כשהגרסה זמינה להתקנה:

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 App Distribution אחרי שהבודק נכנס לחשבון, אפשר להתקשר אל checkForUpdate() כדי לבדוק אם לבודק יש גישה לגרסת build חדשה.

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(), אפשר לעיין במאמרי העזרה של App Distribution בנושא Swift ו-Objective-C.

שלב 4: בנייה ובדיקה של ההטמעה

לבסוף, בונים את האפליקציה ומפיצים את הגרסה לבודקים באמצעות מסוף Firebase כדי לבדוק את ההטמעה.

בApp Distribution מדריך לפתרון בעיות מפורטות דרכים לפתרון בעיות נפוצות, כמו:

  • הבודק לא מקבל התראות באפליקציה
  • הבודק מתבקש להיכנס ל-Google יותר מפעם אחת