본문 바로가기

iOS/Swift

(39)
Info.plist에 중요 정보 숨기고 조회하기 url 이나 api 통신을 위한 key를 Info.plist에 등록하고 api 통신시 조회하여 쓰는 방법 Android의 localproperty처럼 혹시나 모를 상황을 대비하여 api 통신시 사용하는 url과 key를 숨겨두기 위해 Info.plist에 등록하고 사용하였다. 등록한 Key로 Info.plist에서 조회한다. strcut 구조체를 만들어 상황에따라 일괄적으로 변경되어 사용할 수 있게 구성해서 사용하였다. var devUrl: String? { get { guard let filePath = Bundle.main.path(forResource: "Info", ofType: "plist") else { fatalError("Couldn't find file 'Info.plist'.") }..
[iOS] 앱 기본 정보 조회 한 번 만들어두면 쓸때 편한 앱 기본 정보 조회 //앱 버전 조회 func currentAppVersion() -> String { if let info: [String: Any] = Bundle.main.infoDictionary, let currentVersion: String = info["CFBundleShortVersionString"] as? String { return currentVersion } return "nil" } //앱 bundle 조회 func bundleIdentifier() -> String{ if let value = Bundl..
third party library into private cocoapods module private cocoapods library로 모듈화할때 third party libarary를 참조하는 경우 외부 프로젝트에서 사용하는 방법 cocoapodsd library not find 오류 해결 [!] Unable to find a specification for `Alamofire` private cocoapods libarary에서 dependency로 추가한 third party library를 외부 프로젝트에 설치하려는 경우에 발생한 오류 해결 방법 이전 글에서 cocoapods를 이용해 private pods library를 만들어 github로 배포하는 방법에 대해 작성하였다. 이후 만든 pod library를 통해 third party library인 Alamofire로 api ..
create module with private cocoapods priavte cocoapods로 module 만들어 배포하기. 업무상 만들어둔 프로젝트의 일부 기능을 모듈로 만들어 재사용 및 외부에 배포해야 하는 일이 생겨 갖은 검색 끝에 private cocoapods와 private github을 통해 배포하는 방법을 찾았다. public cocoapods는 cocoapods를 통해 관리 및 배포되지만 private cocoapods는 git을 통해 버전 관리 및 배포한다. Spec repository는 버전 관리를 위한 용도이고 Pod repository는 코드를 작성해서 git에 업로드 해둔다. pod를 사용할때는 spec repo에만 접근 가능하고 실제 pod repo를 노출하지 않는다 1. github에 Spec Repo와 Pod Repo 두개의 repo..
[ios - swift] 화면 터치시UITextField 키보드 내리기 및 스크롤 처리 일반적으로 UITextField의 경우 touchBegan에서 endEditing을 사용하여 화면 터치시 UITextField로 인해 올라와있는 키보드를 내릴 수 있지만 UIScrollVIew 안에 있는 UITextField 의 경우 동작하지 않는다. override func touchesBegan(_ touches: Set, with event: UIEvent?) { self.view.endEditing(true) self.scrollView.endEditing(true) self.contentView.endEditing(true) } 따라서 스크롤뷰를 터치할 경우 키보드가 내려가도록 UIGestureRecognizer를 추가해주었다. 또한 키보드가 나타났을 때 키보드가 화면을 가리는 경우도 있기 ..
[ios - swift] coremotion을 이용한 걸음수 조회 애플 건강앱을 연동해 사용자의 걸음기록을 보여주는 기능을 구현하였는데 유저가 권한을 허가하지 않거나 건강앱을 사용하지 않는 경우를 대비해 안드로이드의 자이로 센서를 이용한 걸음수 처럼 애플의 core motion을 이용해 걸음수를 수집하려고 하였다. 애플 건강앱의 데이터를 조회할때와 마찬가지로 일정 기간동안의 특정 타입을 요청하면 해당 기간동안의 합산 수치를 넘겨 받을 수 있다. 애플 건강앱의 기록과 비교해보니 동일한 수치를 넘겨주었던 걸로 보아 애플의 건강앱 또한 core motion을 사용하는 것으로 보인다. import CoreMotion class CoreStepCount{ private let pedometer = CMPedometer() public func getStepCount(){ let..
[ios - swift] apple Healthkit sleep analysis 아이폰의 건강 앱에서 수면 정보를 연동해온다. 사용자가 권한을 변경할 가능성이 있으므로 정보 조회시 마다 해당 정보에 대한 권한을 항상 요청한다. *healthkit pod를 추가해야함 Sleep Analysis는 HKSampleType중 CategoryType으로 특정 시작일자와 끝일자를 기준으로 Sleep Analysis 타입을 HKSampleType을 조회하면 해당 기간동안 등록된 수면 유형에 대한 데이터를 배열로 넘겨 받는다. 조회 결과 : 측정 기기, 수면 유형, 시작시간, 끝시간을 조회 할 수 있음. 예시 : [ 3E92DB26-A2B8-425B-B018-1F73C4****BF 3 3E92DB26-A2B8-425B-B018-1F73C4****BF "Apple Watch" (9.3.1), "Wa..
[ios - swift] keychain var uuid: String { get { //read uuid from keychain return readUUIDfromKeyChain() } } } func readUUIDfromKeyChain() -> String{ let query: [CFString: Any] = [kSecClass: kSecClassGenericPassword, kSecAttrService: Bundle.main.bundleIdentifier as Any, kSecAttrAccount: "\(Bundle.main.bundleIdentifier).uuid", kSecReturnAttributes: kCFBooleanTrue, kSecReturnData: kCFBooleanTrue, kSecMatchLimit: kSecMatc..
[ios - swift] 이미지 공유하기 이미지 공유하기 share Image when button clicked @IBAction func shareImage(_ sender: UIButton) { let vc = UIActivityViewController(activityItems: [sheetView.asImage()], applicationActivities: []) present(vc, animated: true) } ▼ sheetView.asImage() : UIView를 UIImage로 만들기 (make UIView to UIImage ) [ios - swift] save UIView as Image in album 1. add permition for save image in album. 앨범에 이미지를 저장하기 위한 권한 추가...
[ios - swift] 버튼 클릭시 이미지 프린트하기 버튼 클릭시 이미지 프린트하기 being print image when click button @IBAction func printImage(_ sender: UIButton) { let vc = UIPrintInteractionController.shared vc.printingItem = sheetView.asImage() vc.present(animated: true) { (controller, success, errorMsg) in if success { //do someThing when sucess } else { //do something when error } } } ▼ sheetView.asImage() : make UIView to UIImage [ios - swift] save UIV..