如何从 iOS 上的 C++ 代码登录到 Crashlytics?

How can logging to Crashlytics be done from C++ code on iOS?

Crashlytics documentation for iOS only mentions custom logging from Swift and Objective-C. It mentions nothing about doing this from C++. On Android, we can use the log() and set() functions from the Crashlytics native header 从通过 JNI 调用的 C++ 代码进行日志记录。 iOS是否有等效的方法?还有其他方法吗?

这里是 Crashlytics 的托德!现在,如果您端没有某种自定义适配器返回到 Swift 或 Objective-C,这是不可能的。随着 C++ 在高级应用程序中变得越来越普遍,我希望看到团队考虑这一点 :)

是的,我不认为有一个 C 函数可以解决这个问题,但我前段时间遇到了这个问题,我使用了一个函数指针。原来如此。

在 C 范围内(.cpp 和 .h 文件)

    void yourCFunction(void (*logFunc)(const char*) = NULL);

在 ObjectiveC 范围内:

CYourCClass *yourCClass = [...];
yourCClass->yourCFunction( [](const char* t){
    CLS_LOG(@"%s", t);
});

在C++中调用log函数:

if (logFunc!=NULL) {
    std::string debugChr("Some message");
    (*logFunc)(debugChr.c_str());
}

这可以使用宏和其他东西来改进,但你有想法。