9. Server Web Desktop Android iOS
OS API Browser API OS API Android API iOS API
以 Kotlin Multiplatform 共?業務邏輯
Android View SwiftUI
使? Kotlin Multiplatform 技術開發雙平台 Mobile App
—
Kotlin Multiplatform Mobile
13. 透過 Compose Multiplatform 共? UI
—
Server Web Desktop Android iOS
OS API Browser API OS API Android API iOS API
以 Kotlin Multiplatform 共?業務邏輯
以 Compose Multiplatform 共? UI
Android View
Swing SwiftUI
Compose Multiplatform
17. 擴? Compose Multiplatform 版圖
—
Server Web Desktop Android iOS
OS API Browser API OS API Android API iOS API
以 Kotlin Multiplatform 共?業務邏輯
Android View
Swing SwiftUI
Compose Multiplatform
以 Compose Multiplatform 共? UI
以 Compose Multiplatform 共? UI
46. 後端 API 服務
—
Server Client
語法簡單
輕量
適合做微服務
HTTP Client
?援多平台
搭配 kotlinx.serialization 做 SDK
47. 共? Data Class
—
@Serializable
data class LoginRequest(
val username: String,
val password: String,
)
@Serializable
data class LoginResponse(
val result: Boolean,
val message: String,
val user: User? = null,
)
@Serializable
data class User(
val id: Int,
val username: String,
val password: String,
val email: String,
val displayName: String,
val profileImageUrl: String,
)
48. Ktor Server
—
fun main() {
embeddedServer(Netty, port = 8080, host = "0.0.0.0") {
install(ContentNegotiation) {
json()
}
// Ktor plugins
configureLogin()
}.start(wait = true)
}
49. 實作 API Service
—
fun Application.configureLogin() {
routing {
post("...") {
// 接收 HTTP Request
// 反序列化成 Data Class
val req = call.receive<LoginRequest>()
// 登入驗證程式碼
// 回傳 HTTP Response
call.respond(
LoginResponse(
result = ...,
message = "...",
user = loggedInUser,
)
)
}
}
}
51. Kotlin Multiplatform 全版圖
—
Server Web Desktop Android iOS
OS API Browser API OS API Android API iOS API
以 Kotlin Multiplatform 共?業務邏輯
以 Compose Multiplatform 共? UI
Android View
Swing SwiftUI