앱 배포 SDK로 인앱 새 알림 설정

선택사항인 Firebase 앱 배포 SDK를 사용하면 앱의 새 빌드를 설치할 수 있게 되면 테스터에게 인앱 알림을 표시할 수 있습니다. 이 가이드에서는 앱 배포 SDK를 사용하여 테스터를 위한 새 빌드 알림을 만들고 맞춤설정하는 방법을 설명합니다.

시작하기 전에

아직 추가하지 않았다면 iOS 프로젝트에 Firebase를 추가합니다.

1단계: App Distribution Tester API 사용 설정

  1. Google Cloud Console에서 프로젝트를 선택합니다.

  2. Firebase App Testers API에서 사용 설정을 클릭합니다.

2단계: 앱에 앱 배포 추가

CocoaPods를 사용하여 Firebase 라이브러리를 설치하는 것이 좋습니다. 하지만 CocoaPods를 사용하지 않으려는 경우 SDK 프레임워크를 직접 통합할 수 있습니다.

  1. 프로젝트용으로 만든 podfile을 열거나 pod init을 실행하여 podfile을 만든 후 대상 섹션 안에 다음 줄을 추가합니다.

    pod 'Firebase/AppDistribution'
  2. podfile 디렉터리에서 pod install을 실행한 다음 만든 .xcworkspace 파일을 엽니다.

  3. 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
  4. UIApplicationDelegate에서 Firebase 모듈을 가져옵니다.

    Swift

    import Firebase
    

    Objective-C

    @import Firebase;
    
  5. 일반적으로 앱의 application:didFinishLaunchingWithOptions: 메서드에서 FirebaseApp 공유 인스턴스를 구성합니다.

    Swift

    // Use Firebase library to configure APIs
    FirebaseApp.configure()
    

    Objective-C

    // Use Firebase library to configure APIs
    [FIRApp configure];
    
  6. 마지막으로 앱을 다시 컴파일합니다.

3단계: 인앱 알림 구성

앱 배포 SDK는 테스터를 위한 인앱 빌드 알림을 설정하는 두 가지 방법, 즉 테스터에게 표시할 사전 빌드된 로그인 대화상자와 함께 제공되는 기본 알림 구성과 자체 사용자 인터페이스(UI)를 맞춤설정할 수 있는 고급 알림 구성을 제공합니다. SDK를 처음 사용하는 경우 먼저 기본 알림 구성을 사용하는 것이 좋습니다.

기본 구성

checkForUpdate를 사용하여 아직 알림을 사용 설정하지 않은 테스터에게 사전 빌드된 알림 사용 설정 대화상자를 표시한 다음 새 빌드를 사용할 수 있는지 확인합니다. 이 메서드를 호출하면 다음과 같은 순서가 적용됩니다.

  1. Google 계정으로 앱 배포에 로그인하라는 메시지를 표시하여 테스터가 알림을 사용 설정했는지 확인합니다.

  2. 테스터가 아직 알림을 사용 설정하지 않은 경우 사전 빌드된 대화상자를 표시합니다. 알림 사용 설정은 테스트 기기에서 한 번만 진행하면 되며 앱 업데이트 후에도 지속됩니다. 알림을 사용 설정하면 앱이 제거되거나 signOutTester 메서드가 호출될 때까지 기기에서 알림이 사용 설정된 상태로 유지됩니다. 이 고급 구성 메서드에 관한 자세한 내용은 SwiftObjective-C의 앱 배포 참조 문서를 확인하세요.

  3. 테스터가 설치할 수 있는 최신 빌드를 확인합니다.

예를 들어 다음 코드는 테스터가 알림을 사용 설정하고 새 빌드에 액세스할 수 있는지 확인합니다.

Swift

AppDistribution.appDistribution().checkForUpdate(completion: { release, error in
// Includes a pre-built enable alerts dialogue that lets your tester enable alerts.
// You can also customize your own user interface that prompts the tester to
// install a newly available distribution (refer to sample code below).
})

Objective-C

[[FIRAppDistribution appDistribution]
    checkForUpdateWithCompletion:^(FIRAppDistributionRelease *_Nullable release,
                                   NSError *_Nullable error) {
// Includes a pre-built enable alerts dialogue that lets your tester enable alerts.
// You can also customize your own user interface that prompts the tester to
// install a newly available distribution (refer to sample code below).
}];

이 메서드는 언제든지 앱에 포함할 수 있습니다. 예를 들어 UIViewControllerviewDidAppearcheckForUpdate를 포함하여 시작 시 테스터에게 최신 빌드를 설치하라는 메시지를 표시할 수 있습니다.

다음 예시에서는 새 빌드를 설치할 수 있게 되면 테스터에 대화상자를 표시합니다.

Swift

AppDistribution.appDistribution().checkForUpdate(completion: { release, error in
  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) {
  UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Check For Update"
message:[NSString stringWithFormat:@"Error during tester sign in! %@", error.localizedDescription]
preferredStyle:UIAlertControllerStyleAlert];

  UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {}];

  [alert addAction:okAction];
  [self presentViewController:alert animated:YES completion:nil];

  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];
  }
}];

추가 메서드에 대한 자세한 내용은 SwiftObjective-C의 앱 배포 참조 문서를 확인하세요.

고급 구성

signInTesterisTesterSignedIn 메서드를 사용하면 테스터의 로그인 환경을 더 유연하게 맞춤설정할 수 있으므로 앱의 모양과 느낌에 더 적합하게 만들 수 있습니다.

다음 예시에서는 테스터가 Firebase 앱 배포 테스터 계정에 이미 로그인되어 있는지 여부를 확인합니다. 따라서 아직 로그인하지 않은 테스터에 대해서만 로그인 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
  })
}

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를 비롯한 추가 메서드에 대한 자세한 내용은 SwiftObjective-C의 앱 배포 참조 문서를 확인하세요.

4단계: 구현 빌드 및 테스트

마지막으로 Firebase Console을 사용하여 테스터에 빌드를 배포하는 방식으로 앱을 빌드하고 구현을 테스트합니다.

다음과 같은 일반적인 문제에 대한 도움말은 앱 배포 문제 해결 가이드를 참조하세요.

  • 테스터가 인앱 알림을 받지 못함
  • 테스터에게 Google에 로그인하라는 메시지가 두 번 이상 표시됨