51 lines
1.7 KiB
Plaintext
51 lines
1.7 KiB
Plaintext
#import <Foundation/Foundation.h>
|
|
|
|
#import "FirebaseSDK.h"
|
|
#import "FirebaseMessaging/FIRMessaging.h"
|
|
#import "NativeUtils.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef void (*GetFirebaseTokenCallback)(const char* token);
|
|
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) {
|
|
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 (firebaseTokenCallback){
|
|
const char *pConstToken = [token UTF8String];
|
|
firebaseTokenCallback(pConstToken);
|
|
}
|
|
}
|
|
}];
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|