Reputation: 87
The 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 to do logging from C++ code called through the JNI. Is there an equivalent method for iOS? Is there any other way to do it?
Upvotes: 1
Views: 622
Reputation: 313
Yep, I don't think there is a C-function for that but I had the problem some time ago and I used a function pointer. So here it is.
In the C scope (.cpp and .h file)
void yourCFunction(void (*logFunc)(const char*) = NULL);
In the ObjectiveC scope:
CYourCClass *yourCClass = [...];
yourCClass->yourCFunction( [](const char* t){
CLS_LOG(@"%s", t);
});
To call the log function in C++:
if (logFunc!=NULL) {
std::string debugChr("Some message");
(*logFunc)(debugChr.c_str());
}
This can be improved using macro and stuff but you have the idea.
Upvotes: 0
Reputation: 2262
Todd from Crashlytics here! Right now this is not possible without some sort of custom adapter on your end to go back to Swift or Objective-C. As C++ becomes more common in advanced apps I'd expect to see the team consider this :)
Upvotes: 2