51 lines
1.5 KiB
Plaintext
51 lines
1.5 KiB
Plaintext
//
|
|
// UIViewController+Logger.cpp
|
|
// Unity-iPhone
|
|
//
|
|
// Created by Hl Zhang on 2023/3/21.
|
|
//
|
|
|
|
#include <stdio.h>
|
|
#include <string>
|
|
#import "UIViewController+Logger.h"
|
|
#import <Foundation/Foundation.h>
|
|
#import "NSString+Customer.h"
|
|
#import "NSDictionary+Customer.h"
|
|
@import FBSDKCoreKit;
|
|
@import FirebaseAnalytics;
|
|
|
|
@implementation UIViewController (Logger)
|
|
|
|
|
|
|
|
|
|
-(void)logEvent:(NSString *)content{
|
|
if ([NSString isStringEmpty:content]) {
|
|
NSLog(@"Content is empty");
|
|
return;
|
|
}
|
|
NSDictionary *jsonDict = [NSDictionary parseJSONString:content];
|
|
if (jsonDict == nil) {
|
|
NSLog(@"Error parsing JSON string");
|
|
return;
|
|
}
|
|
NSString *name = jsonDict[@"name"];
|
|
if ([NSString isStringEmpty:name]) {
|
|
name = @"custom_event";
|
|
}
|
|
// NSLog(@"FacebookAdvertiserIDCollectionEnabled: %@", [[FBSDKSettings sharedSettings] isAdvertiserIDCollectionEnabled] ? @"TRUE" : @"FALSE" );
|
|
// NSLog(@"FacebookAdvertiserTrackingEnabled: %@", [[FBSDKSettings sharedSettings] isAdvertiserTrackingEnabled] ? @"TRUE" : @"FALSE" );
|
|
[FIRAnalytics logEventWithName: name parameters: jsonDict];
|
|
[[FBSDKAppEvents shared] logEvent: name parameters: jsonDict];
|
|
}
|
|
|
|
|
|
extern "C" void nativeLogEvent(const char *content) {
|
|
NSString *contentStr = [NSString stringWithCString:content encoding: NSUTF8StringEncoding];
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
|
|
[window.rootViewController logEvent: contentStr];
|
|
});
|
|
}
|
|
@end
|