source

TestFlight 베타 설치를 통해 iOS 앱이 실행 중인지 런타임에 확인하는 방법

factcode 2023. 7. 13. 21:10
반응형

TestFlight 베타 설치를 통해 iOS 앱이 실행 중인지 런타임에 확인하는 방법

앱 스토어와 비교하여 테스트 플라이트 베타(iTunes Connect를 통해 제출)를 통해 애플리케이션이 설치되었음을 런타임에 감지할 수 있습니까?단일 앱 번들을 제출하고 둘 다 사용할 수 있습니다.어떤 방식으로 설치되었는지 감지할 수 있는 API가 있습니까?아니면 영수증에 이것을 확인할 수 있는 정보가 포함되어 있습니까?

TestFlight Beta를 통해 설치된 애플리케이션의 경우 영수증 파일 이름이 지정됩니다.StoreKit/sandboxReceipt평소와 비교하여StoreKit/receipt.사용.[NSBundle appStoreReceiptURL]URL 끝에서 sandboxReceipt를 찾을 수 있습니다.

NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSString *receiptURLString = [receiptURL path];
BOOL isRunningTestFlightBeta =  ([receiptURLString rangeOfString:@"sandboxReceipt"].location != NSNotFound);

참고:sandboxReceipt로컬로 빌드를 실행할 때와 시뮬레이터에서 실행할 빌드에 대한 영수증 파일의 이름이기도 합니다.

빠른 버전:

let isTestFlight = Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt"

조합의 답변을 바탕으로 다음과 같은 SWIFT 도우미 클래스를 만들었습니다.이 클래스를 사용하여 디버그, 테스트 비행 또는 앱스토어 빌드 여부를 확인할 수 있습니다.

enum AppConfiguration {
  case Debug
  case TestFlight
  case AppStore
}

struct Config {
  // This is private because the use of 'appConfiguration' is preferred.
  private static let isTestFlight = Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt"
  
  // This can be used to add debug statements.
  static var isDebug: Bool {
    #if DEBUG
      return true
    #else
      return false
    #endif
  }

  static var appConfiguration: AppConfiguration {
    if isDebug {
      return .Debug
    } else if isTestFlight {
      return .TestFlight
    } else {
      return .AppStore
    }
  }
}

프로젝트에서 다음 방법을 사용하여 환경별로 서로 다른 추적 ID 또는 연결 문자열을 제공합니다.

  func getURL(path: String) -> String {    
    switch (Config.appConfiguration) {
    case .Debug:
      return host + "://" + debugBaseUrl + path
    default:
      return host + "://" + baseUrl + path
    }
  }

OR:

  static var trackingKey: String {
    switch (Config.appConfiguration) {
    case .Debug:
      return debugKey
    case .TestFlight:
      return testflightKey
    default:
      return appstoreKey
    }
  }

업데이트 05-02-2016: DEBUG가 일부 Swift 컴파일러 사용자 지정 플래그를 설정하려면 #와 같은 전처리기 매크로를 사용해야 합니다.자세한 내용은 다음 답변을 참조하십시오. https://stackoverflow.com/a/24112024/639227

(승인된 답변 기준) Simulators를 설명하는 최신 Swift 버전:

private func isSimulatorOrTestFlight() -> Bool {
    guard let path = Bundle.main.appStoreReceiptURL?.path else {
        return false
    }
    return path.contains("CoreSimulator") || path.contains("sandboxReceipt")
}

내선번호를 사용Bundle+isProductionSwift 5.2에서:

import Foundation

extension Bundle {
    var isProduction: Bool {
        #if DEBUG
            return false
        #else
            guard let path = self.appStoreReceiptURL?.path else {
                return true
            }
            return !path.contains("sandboxReceipt")
        #endif
    }
}

그러면:

if Bundle.main.isProduction {
    // do something
}

프로젝트에 사용하는 한 가지 방법이 있습니다.단계는 다음과 같습니다.

Xcode에서 프로젝트 설정(대상이 아닌 프로젝트)으로 이동하고 목록에 "베타" 구성을 추가합니다.

enter image description here



그런 다음 "베타" 구성으로 프로젝트를 실행할 새 구성표를 만들어야 합니다.구성표를 만들려면 여기를 클릭하십시오.

enter image description here



이 계획에 원하는 이름을 대세요.이 구성표에 대한 설정을 편집해야 합니다.이 작업을 수행하려면 여기를 누릅니다.

enter image description here



선택할 수 있는 보관 탭 선택Build configuration

enter image description here



그러면 키를 추가해야 합니다.Config가치 있는$(CONFIGURATION)프로젝트 정보 속성 목록은 다음과 같습니다.

enter image description here



그렇다면 베타 빌드에 특정한 작업을 수행하기 위해 코드에서 무엇이 필요한지가 문제입니다.

let config = Bundle.main.object(forInfoDictionaryKey: "Config") as! String
if config == "Debug" {
  // app running in debug configuration
}
else if config == "Release" {
  // app running in release configuration
}
else if config == "Beta" {
  // app running in beta configuration
}

언급URL : https://stackoverflow.com/questions/26081543/how-to-tell-at-runtime-whether-an-ios-app-is-running-through-a-testflight-beta-i

반응형