オプションのFirebaseAppDistributioniOSおよびAndroidSDKを使用すると、アプリの新しいビルドをインストールできるようになったときに、テスターにアプリ内アラートを表示できます。このガイドでは、App DistributioniOSおよびAndroidSDKを使用して、テスター向けの新しいビルドアラートを作成およびカスタマイズする方法について説明します。
あなたが始める前に
まだ行っていない場合は、iOSプロジェクトにFirebaseを追加します。
ステップ1 :App DistributionTesterAPIを有効にする
GoogleCloudConsoleでプロジェクトを選択します。
Firebase App Testers APIで、[有効にする]をクリックします。
ステップ2 :アプリにアプリディストリビューションを追加する
プロジェクト用に作成したPodfileを開き(または
pod init
を実行して作成し)、ターゲットセクション内に次の行を追加します。pod 'FirebaseAppDistribution'
podfileのディレクトリで、
pod install
を実行し、作成した.xcworkspace
ファイルを開きます。GoogleアプリIDをエンコードします( iOSバージョン9および10にのみ必要):
GoogleアプリIDをエンコードします
Info.plist file
にスニペットを含めてappdistribution-<encoded-google-app-id>
URLスキームを追加します(XcodeでURLスキームを追加する方法については、 Appleのドキュメントを参照してください)。<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>
次に、コロン(:)をダッシュ(-)に置き換えて、GoogleアプリIDをエンコードします。 GoogleアプリIDは
GoogleService-Info.plist
ファイルにあることに注意してください。たとえば、GoogleアプリIDが次の場合:7:77777777777:ios:123456789
エンコードされたGoogleアプリIDは次のとおりです。
7-77777777777-ios-123456789
App
構造体またはUIApplicationDelegate
にFirebaseモジュールをインポートします。迅速
import FirebaseCore
Objective-C
@import FirebaseCore;
通常、
App
のイニシャライザーまたはアプリデリゲートのapplication(_:didFinishLaunchingWithOptions:)
メソッドでFirebaseApp
共有インスタンスを構成します。迅速
// Use Firebase library to configure APIs FirebaseApp.configure()
Objective-C
// Use Firebase library to configure APIs [FIRApp configure];
最後に、アプリを再コンパイルします。
ステップ3 :アプリ内アラートを構成する
App Distribution SDKは、テスターにアプリ内ビルドアラートを設定する2つの方法を提供します。テスターに表示するビルド済みのアプリの更新とサインインダイアログが付属する基本的なアラート構成と、テスターに表示する高度なアラート構成です。独自のユーザーインターフェイスをカスタマイズします。 App Distribution SDKを初めて使用する場合は、最初に基本的なアラート構成を使用することをお勧めします。
基本構成
checkForUpdate
を使用して、アラートをまだ有効にしていないテスターにビルド済みのアラートの有効化ダイアログを表示し、新しいビルドが利用可能かどうかを確認します。呼び出されると、メソッドは次のシーケンスを実行します。
テスターがGoogleアカウントでAppDistributionにサインインするように促すことで、アラートが有効になっているかどうかを確認します。
テスターがアラートをまだ有効にしていない場合は、事前に作成されたダイアログを表示します。
アラートの有効化は、テストデバイスでの1回限りのプロセスであり、アプリの更新後も継続します。アプリがアンインストールされるか、
signOutTester
メソッドが呼び出されるまで、アラートはテストデバイスで有効のままになります。詳細については、メソッドのリファレンスドキュメント( SwiftまたはObjective-C )を参照してください。テスターがインストールするために新しく利用可能なビルドをチェックします。
アプリの任意の時点でcheckForUpdate()
を呼び出すことができます。たとえば、アプリのルートビューのonAppear(perform:)
にcheckForUpdate()
を含めることで、起動時に新しく利用可能なビルドをインストールするようにテスターに促すことができます。
次の例では、テスターがアラートを有効にして新しいビルドにアクセスできるかどうかを確認し、有効になっている場合は、ビルドがインストール可能になったときにダイアログを表示します。
迅速
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()
を呼び出して、テスターが新しいビルドにアクセスできるかどうかを確認します。
迅速
// 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()
を含む追加のメソッドについては、 SwiftおよびObjective-CのAppDistributionリファレンスドキュメントを参照してください。
ステップ4 :実装を構築してテストする
最後に、Firebaseコンソールを使用してビルドをテスターに配布することで、アプリをビルドし、実装をテストします。
次のような一般的な問題については、アプリ配布のトラブルシューティングガイドをご覧ください。
- テスターがアプリ内アラートを受信しない
- テスターはGoogleに複数回サインインするように求められます