2020 Monthly I Learned - kirseia/study GitHub Wiki

2020.12
  • AVAudioEngine 을 활용한 녹음기 개발

    • 핵심은 mixer.volume = 0으로 입력단에서의 소음 제거(녹음기 소리만 뽑기),
    • engine.connect(mixerNode, to: engine.mainMixerNode, format: mixerFormat) 으로 mainMixerNode 로 연결하는 것 (engine.outputNode 가 아니라)
    • outputNode로 연결하면 마이크 입력값이 스피커로 출력되어 다시 마이크로 입력되는 현상이 발생할 수 있음
  • 로컬 푸시 등록 및 처리 1, 2

    • 로컬 푸시에 이미지를 추가할때는 move 되기 때문에 사용할 이미지를 복사해서 url을 넘겨줘야 함
    • (but, main bundle 이미지는 복사됨)
  • UserNotifications

  • Share Extension 관련 정리, [2]

- 사진 에서 공유 시 phasset 이 아니라 image url이 들어옴
- image orientation 이 살아있는 상태 -> 사용 방식에 따라 UIImage.Orientation.up 으로 보정 필요.
- Extension 과 Host app 사이에 데이터 주고 받기가 안되기 때문에 image url 을 파일로 저장해도 Host app 에서 로드가 안됨, App groups를 활용해야 함
- Host app 이 multi targets 이고, Share Extension 은 하나일때는 Host app에서 빌드할때 embed 이후에 re-signing 과정이 필요함
- Ref. https://stackoverflow.com/questions/25398636/ios-extensions-with-multiple-targets
- Ref. https://gist.github.com/damian-rzeszot/0b23ad87e5ab5d52aa15c095cbf43c59
2020.11
  • 시스템에 있는 폰트 불러오기
UIFont.systemFont(...) 으로는 기본 폰트만 로드 가능
for familyName in UIFont.familyNames {
  for fontName in UIFont.fontNames(forFamilyName: fontFamilyName) {
     // 이렇게 하면 로드가 안됨. 시스템 폰트만 로드됨
     let font_x = UIFont.font(with: fontName, fontSize: 10) 

     // 이렇게 해야 됨, 이유는 모름.;
     let description = UIFontDescriptor(name: fontName, size: 10)
     let font_o = UIFont(descriptor: description, size: 10)
  }
}
  • 각 플랫폼 공유 기능 정리
- 인스타  - > 필수 - 최소 3초, 최대 10분, 최소 640x640 
    - "instagram://library?LocalIdentifier=\(assetIdentifier)&InstagramCaption=\(tagString)")
    - 위 스킴으로 피드/스토리 업로드 페이지로 바로 이동 가능 - 비공개 스팀
    - https://developers.facebook.com/docs/instagram/sharing-to-feed
 
- 인스타 스토리 - 필수 - 최대 20초, 옵션 - 1080p , 50메가 미만 
    - "instagram-stories://share?source_application=\(bundleIdentifier)"
    - scheme + pastebox 활용해서 공유 가능 
    - https://developers.facebook.com/docs/instagram/sharing-to-stories/

- 유튜브 - api 로 업로드 해야 함, 최대 128기가
    - youtube://upload scheme (비공개 스팀) 으로 생성 페이지로 바로 접근 가능
    - https://developers.google.com/youtube/v3/docs/videos/insert

- 틱톡 - sdk 필요,
    - 2초 ~ 60초 사이, 워터마크 있으면 삭제 될 수 있음. 500메가 제한, 1080p 여야 함. 
    - https://boosted.lightricks.com/tiktok-video-length-video-formatting-guide/

- 페북 - sdk 필요 (들어있음, 사용 가능)
    - 동영상, 50메가 미만
    - https://developers.facebook.com/docs/sharing/sharing-to-stories/ios-developers/

- 라인	 sdk 필요 
    - 300메가, 1.5분이 제한 

- wechat sdk 필요
    - 100메가 제한
    - https://developers.facebook.com/docs/whatsapp/api/media/

- qq 메신져  sdk 필요
- 와츠앱 
    - https://faq.whatsapp.com/iphone/how-to-link-to-whatsapp-from-a-different-app/?lang=kr
2020.10
let a: Any = 120
if let b = a as? Int {
    // 0.011 s 
}
보다 
let a: Any = 120
if case let b as Int = a {
    // 0.001 s
}
2020. 9
2020. 8
2020. 7
2020. 6
2020. 5
2020. 4
AppDelegate.applicationDidReceiveMemoryWarning(_:) <- 이게 가장 먼저 호출됨
UIApplicationDidReceiveMemoryWarningNotification
UIViewController.didReceiveMemoryWarning() <- 마지막 호출 됨
    static var totalMemorySpace: UInt64 {
        ProcessInfo.processInfo.physicalMemory / UInt64(1024 * 1024)
    }

    static var usedMemorySpace: UInt64 {
        // The `TASK_VM_INFO_COUNT` and `TASK_VM_INFO_REV1_COUNT` macros are too
        // complex for the Swift C importer, so we have to define them ourselves.
        let TASK_VM_INFO_COUNT = mach_msg_type_number_t(MemoryLayout<task_vm_info_data_t>.size / MemoryLayout<integer_t>.size)
        guard let memoryLayout = MemoryLayout.offset(of: \task_vm_info_data_t.min_address) else {
            return 0
        }
        
        let TASK_VM_INFO_REV1_COUNT = mach_msg_type_number_t(memoryLayout / MemoryLayout<integer_t>.size)
        var info = task_vm_info_data_t()
        var count = TASK_VM_INFO_COUNT
        let kr = withUnsafeMutablePointer(to: &info) { infoPtr in
            infoPtr.withMemoryRebound(to: integer_t.self, capacity: Int(count)) { intPtr in
                task_info(mach_task_self_, task_flavor_t(TASK_VM_INFO), intPtr, &count)
            }
        }
        
        guard kr == KERN_SUCCESS, count >= TASK_VM_INFO_REV1_COUNT else {
            return 0
        }
        
        return info.phys_footprint / UInt64(1024 * 1024)
    }
2020. 3
2020. 2
// average: 0.315 seconds (macOS Sierra 10.12.5)
func testInitializedArrayPerformance() {
    self.measure {
        var array = [Float](repeating: 1, count: 2048 * 2048)
        for i in 0..<array.count {
            array[(i+1)%array.count] = Float(i)
        }
    }
}

// average: 0.043 seconds (macOS Sierra 10.12.5)
func testUninitializedArrayPerformance() {
    self.measure {
        var array : [Float] = []
        array.reserveCapacity(2048 * 2048) <- 젤 빠름
        array.append(0)
        for i in 0..<(2048 * 2048) {
            array.append(Float(i))
        }
        array[0] = Float(2048 * 2048-1)
    }
}

// average: 0.077 seconds (macOS Sierra 10.12.5)
func testNativeArrayPerformance() {
    self.measure {
        let count = 2048 * 2048
        let array = UnsafeMutablePointer<Float>.allocate(capacity: count)
        for i in 0..<count {
            array[(i+1)%count] = Float(i)
        }
        array.deallocate(capacity: count)
    }
}
[[UIApplication sharedApplication] performSelector:@selector(_performMemoryWarning)];
    func testTuple() {
        let (a, b) = makeTuple()
        print(a)
        print(b)
    }
    
    func makeTuple() -> (Int, Int) {
        return (1, 1)
    }
2020. 1
post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO' 
      config.build_settings['DEBUG_INFORMATION_FORMAT'] = 'dwarf'
      config.build_settings['VALID_ARCHS'] = 'arm64'
    end
  end
end

+ carthage 쪽은 빌드 할 때 '--no-use-binaries' 옵션을 준다

In Xcode, look in Build Settings for “Strip Debug Symbols During Copy” (COPY_PHASE_STRIP). When enabled, debug symbols are omitted from your .app and placed into a .dSYM file. Otherwise your .app contains these symbols. (By default, debug symbols are stripped from release builds for reasons of obfuscation. You probably shouldn’t change this setting for the release configuration.)
  • AVAudioMixParameters 에서 audioPitchAlgorithm 을 영상 배속이 빠를 경우 timeDomain / spectral 이 계산량이 varispeed 보다 높거나 낮음에도 불구하고 비정상 동작을 함, varispeed의 경우 계산량은 중간이지만 pitch correction 이 빠져서인지, 이유는 모르겠지만 정상동작 함. (composition 구성시에 재생은 잘되나, export 가 안되는 현상이 있었음)
  • 기기에서 H.265 지원하는지 확인하기
let isHEVC = AVOutputSettingsAssistant.availableOutputSettingsPresets().contains(.hevc3840x2160)
    /* Sent when a download task that has completed a download.  The delegate should
     * copy or move the file at the given location to a new location as it will be
     * removed when the delegate message returns. URLSession:task:didCompleteWithError:
     * will still be called. */

    URLSession 으로 파일을 받고 결과 delegate 내에서 파일을 복사하거나 이동시켜야지, 해당 delegate가 종료되면 파일이 사라져버린다. 
    main.queue 에서 해당 작업을 하려고 했더니 가끔 다운받은 파일이 사라지는 현상이 있어서 수정했었다.;;;
⚠️ **GitHub.com Fallback** ⚠️