Problem:
- Required to share KMM library with linked Xcode Frameworks to other KMM projects
- Xcode project is use Cocoapods
- KMM project (library consumer) is built by Xcode with
:embedAndSignAppleFrameworkForXcode
How to:
| fun <Element> AsyncResult.Companion.fromCoroutine( | |
| source: suspend () -> Element | |
| ): AsyncResult<Element> { | |
| return create { emitter -> | |
| val job = CoroutineScope(defaultDispatcher).launch { | |
| try { | |
| val result = source.invoke() | |
| emitter.onSuccess(result.makeShared()) | |
| } catch (error: Throwable) { |
| class AsyncResult<Element>( | |
| private val source: (AsyncResultEmitter<Element>) -> Unit | |
| ) { | |
| fun subscribe( | |
| onSuccess: (Element) -> Unit, | |
| onError: (Throwable) -> Unit | |
| ): AsyncResultDisposable { | |
| val emitter = AsyncResultEmitter(onSuccess, onError) |
| import AVFoundation | |
| open class ImageVideoGenerator { | |
| public static func generateVideo(image: CGImage, duration: TimeInterval, frameSize: CGSize) throws -> URL { | |
| let outputURL = URL.createTempFile() | |
| let videoWriter = try AVAssetWriter(outputURL: outputURL, fileType: .mp4) | |
| let videoSettings: [String: Any] = [AVVideoCodecKey: AVVideoCodecType.h264, |
| stages: | |
| - deploy | |
| - notification | |
| .send-mt-notification: &send-mt-notification | | |
| curl -X POST \ | |
| $WEBHOOK_URL \ | |
| -H 'Content-Type: application/json' \ | |
| -d "{ | |
| \"channel\": \"town-square\", |
| // STEP 1 - load resources | |
| let asset = AVURLAsset(url: videoURL, options: nil) | |
| let track = asset.tracks(withMediaType: AVMediaType.video) | |
| let videoTrack = track[0] as AVAssetTrack | |
| // STEP 2 - Prepare new layers to video. |
| const int RED_PIN = 10; | |
| const int YELLOW_PIN = 11; | |
| const int GREEN_PIN = 12; | |
| void setup() { | |
| pinMode(RED_PIN, OUTPUT); | |
| pinMode(YELLOW_PIN, OUTPUT); | |
| pinMode(GREEN_PIN, OUTPUT); | |
| } |