Skip to content

Commit

Permalink
[D-0] ocr api key 변경 및 xcconfig 통해 숨김 처리(506) + OCR 카메라 자동 초점 포커스 기능 …
Browse files Browse the repository at this point in the history
…구현(510) (#72)

* fix: ocr-api-key 변경 및 .xcconfig를 통해 key 가져오기

* feat: OCR Camera 초점 조절 구현
  • Loading branch information
Siwon-L committed Sep 30, 2024
1 parent e8404c8 commit 4054a2b
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ jobs:
env:
KEYCHAIN_NAME: ${{ secrets.KEYCHAIN_NAME }}
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}

- name: Setting Xcconfig
run: |
echo "NAVER_OCR_KEY = $NAVER_OCR_KEY" > Projects/App/Resources/APIKey.xcconfig
env:
NAVER_OCR_KEY: ${{secrets.NAVER_OCR_KEY}}

- name: Tuist generate
run: tuist generate
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@ Moneymong.app.dSYM.zip
*.ipa
fastlane/report.xml
fastlane/README.md
Projects/App/Resources/APIKey.xcconfig
7 changes: 6 additions & 1 deletion Projects/App/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ let project = Project(
.marketingVersion("1.2.1")
.swiftVersion("5.7")
.currentProjectVersion("10")
.appleGenericVersioningSystem()
.appleGenericVersioningSystem(),
configurations: [
.debug(name: .debug, xcconfig: "Resources/APIKey.xcconfig"),
.release(name: .release, xcconfig: "Resources/APIKey.xcconfig")
]
),
targets: [
Target(
Expand All @@ -35,6 +39,7 @@ let project = Project(
]
],
"UIUserInterfaceStyle": "Light",
"NAVER_OCR_KEY": "$(NAVER_OCR_KEY)",
"CFBundleShortVersionString": "$(MARKETING_VERSION)",
"CFBundleVersion": "$(CURRENT_PROJECT_VERSION)",
"UILaunchStoryboardName": "LaunchScreen",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ extension LedgerAPI: TargetType {
case .uploadImage: return ["Content-Type": "multipart/form-data"]
case .deleteImage: return ["Content-Type": "application/json"]
case .receiptOCR:
let key = Bundle.main.infoDictionary?["NAVER_OCR_KEY"] as? String
return [
"Content-Type": "multipart/form-data",
"X-OCR-SECRET": "WUdRdW9Ld0FobXRIaVRnYmNBY3NYVVhDdkhDR1lRcHQ="
"X-OCR-SECRET": key ?? ""
]
default: return ["Content-Type": "application/json;charset=UTF-8"]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,18 @@ final class CameraView: UIView {
}

func setupCamera() throws {
// 사용 가능한 카메라 중 후면 카메라를 선택
guard let backCamera = AVCaptureDevice.default(for: .video),
let deviceTypes: [AVCaptureDevice.DeviceType] = [
.builtInTripleCamera, // 최신 프로 모델의 트리플 카메라
.builtInDualCamera, // 듀얼 카메라 (프로 및 일부 비프로 모델)
.builtInWideAngleCamera // 광각 카메라 (단일 렌즈 카메라)
]

// 사용 가능한 장치 중 후면 카메라와 일치하는 장치를 찾기
guard let backCamera = AVCaptureDevice.DiscoverySession(
deviceTypes: deviceTypes,
mediaType: .video,
position: .back
).devices.first,
let input = try? AVCaptureDeviceInput(device: backCamera) else {
throw MoneyMongError.appError(.cameraAccess, errorMessage: "설정에서 카메라 접근을 허용해주세요!")
}
Expand All @@ -63,12 +73,31 @@ final class CameraView: UIView {
// 프리뷰 레이어 설정
videoPreviewLayer.session = captureSession

// 자동 초점 조절
try configureCameraFocus(backCamera)

// 세션 시작
DispatchQueue.main.async {
self.captureSession.startRunning()
}
}

private func configureCameraFocus(_ camera: AVCaptureDevice) throws {
try camera.lockForConfiguration()

// 연속 자동 초점 모드 설정
if camera.isFocusModeSupported(.continuousAutoFocus) {
camera.focusMode = .continuousAutoFocus
}

// 연속 자동 노출 모드 설정
if camera.isExposureModeSupported(.continuousAutoExposure) {
camera.exposureMode = .continuousAutoExposure
}

camera.unlockForConfiguration()
}

var takePhoto: Binder<Void> {
return Binder(self) { owner, _ in
guard let delegate = owner.delegate else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ final class CreateOCRLedgerVC: UIViewController, View {
.alignItems(.center)
.justifyContent(.center)
.height(deviceHeight * 0.175)
}
}.backgroundColor(.black)

cameraView.addSubview(captureImageView)
view.addSubview(topContainer)
topContainer.addSubview(topGuideLine)
Expand Down
3 changes: 3 additions & 0 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ platform :ios do
# 테스트 플라이트 업로드
desc "Push to TestFlight"
lane :tf do |options|

ENV["FASTLANE_XCODEBUILD_SETTINGS_TIMEOUT"] = "120"

# 앱스토어 커넥트 키 연결
app_store_connect_api_key(
key_id: "#{FASTLANE_API_KEY_ID}",
Expand Down

0 comments on commit 4054a2b

Please sign in to comment.