#import #import "FirebaseSDK.h" #import "NativeUtils.h" #ifdef __cplusplus extern "C" { #endif typedef void (*GetFirebaseTokenCallback)(const char* token); @property (nonatomic) GetFirebaseTokenCallback firebaseTokenCallback; // 初始化SDK void FIRInitialize() { [[FirebaseSDK getInstance] initialize]; } // 设置公共事件属性 void FIRSetUserProperty(const char* key, const char* property) { [[FirebaseSDK getInstance] setUserPropertyString:[NSString stringWithFormat:@"%s", property] forName:[NSString stringWithFormat:@"%s", key]]; } void FIRLogEvent(const char* eventName, const char* properties) { [[FirebaseSDK getInstance] logEventWithName:[NSString stringWithFormat:@"%s", eventName] parameters:[NativeUtils convertJsonToDictionary:properties]]; } // log crash void FIRLogCrashCustomKey(const char* key, const char* stack) { [[FirebaseSDK getInstance] logCrash:[NSString stringWithFormat:@"%s", key] stack:[NSString stringWithFormat:@"%s", stack]]; } void FIRGetToken(GetFirebaseTokenCallback callback) { self.firebaseTokenCallback = callback; [[FIRMessaging messaging] tokenWithCompletion:^(NSString *token, NSError *error) { if (error != nil) { NSLog(@"Error getting FCM registration token: %@", error); } else { NSLog(@"FCM registration token: %@", token); if (self.firebaseTokenCallback){ const char *pConstToken = [token UTF8String]; self.firebaseTokenCallback(pConstToken); } } }]; } #ifdef __cplusplus } #endif