最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

firebase - Global function access repository without value-parameter: KMP Multiplatform - Stack Overflow

programmeradmin3浏览0评论

Multiplatform project trying to use Firebase Analytics and Crashytics. I have room setup and offer backup for the database to firebase storage. In the database I have a settings table so user setup will transfer to new device when user logs into new device. All queries go through a repository (BBRepository). I'm trying to access the repository functions using a global function so both Android and IOS can call the global function on startup and return 0/1 for whether the user opts in or out of sharing crashlytics and will also use for analytics. I'm having issues with "no value passed for parameter bbRepository" when calling the global function. What am I missing?

global function:

   fun crashlyticsOption(bbRepository: BBRepository):Int{
    return runBlocking { bbRepository.checkCrashReportConsent() }
}

Android onCreate()

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)


        val crashReportConsent = crashlyticsOption() //<-"No Value Passed for bbRepository"

        Firebase.initialize(this)

        if(crashReportConsent == 1){
            Firebase.crashlytics.setCrashlyticsCollectionEnabled(true)
        }else{Firebase.crashlytics.setCrashlyticsCollectionEnabled(false)}



        setContent {
            App(
                darkTheme = isSystemInDarkTheme(),
                dynamicColor = false,
            )
        }

    }

BBRepository:

interface BBRepository {
   suspend fun checkUseReportConsent(): Int
}

DefaultBBRepository:

class DefaultBBRepository(
    private val bbDao: BBDao,
    private val auth: FirebaseAuth,
    private val uploader: DefaultFileUploader
): BBRepository {

    override suspend fun checkCrashReportConsent(): Int {
            return bbDao.checkCrashReportConsent()
        }
}

bbDAO:

@Dao
interface BBDao {

    @Query("SELECT COUNT(*)!=0 FROM settings WHERE crashReports=1")
        suspend fun checkCrashReportConsent(): Int
}

If I put (bbRepository = BBRepository) into the () at the error, it says BBRepository has no companion object and thus must be initialized here. Also the IOS side is not going to let me initialize BBRepository as it's in the SharedCommon Kotlin code.

I also want to apply the same approach to performing tasks onPause() when the database runs a backup using a global function called from each Platform

发布评论

评论列表(0)

  1. 暂无评论