Wojciech
04/08/2024, 3:55 PMAna Sekuloski
04/09/2024, 7:38 AMWojciech
04/09/2024, 1:40 PMAndroidView(
modifier = Modifier.fillMaxWidth(),
factory = { context ->
AdView(context).apply { }
}
)
but iOS does not, so I can not use AdMob iOS API to present ad.Ana Sekuloski
04/09/2024, 2:55 PMWojciech
04/09/2024, 3:22 PMexpect class Platform {
fun initAdNetwork()
@Composable
fun bannerAd(): AdConfig
}
In Android it is easy to implement it:
actual class Platform(
private val context: Context
) {
@Composable
actual fun adView(adConfig: AdConfig) {
AndroidView(
modifier = Modifier.fillMaxWidth(),
factory = { context ->
AdView(context).apply {
adUnitId = adConfig.adId
loadAd(AdRequest.Builder().build())
}
}
)
}
}
and that is because we got AndroidView()
whch work as wrapper to ppaltform specific android views. Also implementation is on Android project.
However for iOS we got iosMain
project which is separate from iosApp (swift code). And now I am looking for a “bridge” between ios module <-> swift project where I can write actual implementation:
actual class Platform() {
@Composable
actual fun adView(adConfig: AdConfig) {
IosView( <--- this class not exists
modifier = Modifier.fillMaxWidth(),
factory = { context ->
GADBannerView(...) <--- GADBannerView is not accesible from ios module because it is swift project class.
}
)
}
}
Ana Sekuloski
04/09/2024, 4:14 PMadView()
and just initialize and use the views in swift/android projects? or you need the adView()
function in the shared code somewhere?Wojciech
04/09/2024, 4:17 PMEmirhan Emmez
05/30/2024, 12:05 PMWojciech
06/01/2024, 2:05 PMEmirhan Emmez
06/01/2024, 2:06 PMEmirhan Emmez
06/01/2024, 2:06 PMWojciech
06/16/2024, 3:23 PMEmirhan Emmez
06/19/2024, 7:13 PMWojciech
06/19/2024, 7:20 PMEmirhan Emmez
06/19/2024, 7:37 PMAppDelegate.swift
) and call in your iOSApp.swift
• After that add swiftui component from AdBannerView.swift
. There was some crash when you didn't give specific height to banner. So I gave 50. It's working fine.
• Give a lambda parameter to your MainViewController fun like in MainViewController.kt
. UIKitViewController is your banner view. You can freely transfer inside composables (I did like that)
• And finally describe lambda parameter for MainViewController in ContentView.swift
.
If you need help let me know