2023-12-26 04:22:19 +00:00
|
|
|
// ==============================================
|
|
|
|
|
// U3DConsent.mm
|
|
|
|
|
// UnityFramework
|
|
|
|
|
//
|
|
|
|
|
// Created by EricHu on 2022/11/17.
|
|
|
|
|
// Copyright © 2022 guru. All rights reserved.
|
|
|
|
|
// ==============================================
|
|
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
#import <GuruConsent/GuruConsent-Swift.h>
|
|
|
|
|
#import "UnityAppController+UnityInterface.h"
|
|
|
|
|
|
|
|
|
|
@interface U3DConsent : NSObject
|
|
|
|
|
|
|
|
|
|
//+ (void)requestGDPR: (NSString *)deviceId :(int) debugGeo;
|
|
|
|
|
//+ (UIViewController *) getUnityViewController;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
static NSString *gameobjectName;
|
|
|
|
|
static NSString *callbackName;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation U3DConsent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+(UnityAppController *)GetAppController
|
|
|
|
|
{
|
|
|
|
|
return (UnityAppController*)[UIApplication sharedApplication].delegate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+(UIViewController *) getUnityViewController {
|
|
|
|
|
return UnityGetGLViewController();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 请求GDPR的接口
|
|
|
|
|
+(void) requestGDPR: (NSString *)deviceId :(int)debugGeography
|
|
|
|
|
{
|
|
|
|
|
// NSLog(@"--- deviceId: %@", deviceId);
|
|
|
|
|
if(deviceId.length){
|
|
|
|
|
NSLog(@"--- set debug device Id: %@", deviceId);
|
|
|
|
|
GuruConsentDebugSettings *debug = [[GuruConsentDebugSettings alloc] init];
|
|
|
|
|
debug.testDeviceIdentifiers = @[deviceId];
|
|
|
|
|
debug.geography = (GuruConsentDebugSettingsGeography)debugGeography;
|
|
|
|
|
GuruConsent.debug = debug;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 开始请求
|
|
|
|
|
[GuruConsent startFrom: [U3DConsent getUnityViewController]
|
|
|
|
|
success:^(enum GuruConsentGDPRStatus status) {
|
|
|
|
|
|
|
|
|
|
if (@available(iOS 14, *)) {
|
|
|
|
|
// NSLog(@"ATT 结果: %lu",
|
|
|
|
|
// (unsigned long)ATTrackingManager.trackingAuthorizationStatus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSString *msg = @"";
|
|
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
|
case GuruConsentGDPRStatusUnknown:
|
|
|
|
|
NSLog(@"--- GuruConsentGDPRStatusUnknown");
|
|
|
|
|
msg = @"GuruConsentGDPRStatusUnknown";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GuruConsentGDPRStatusRequired:
|
|
|
|
|
NSLog(@"--- GuruConsentGDPRStatusRequired");
|
|
|
|
|
msg = @"GuruConsentGDPRStatusRequired";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GuruConsentGDPRStatusNotRequired:
|
|
|
|
|
NSLog(@"--- GuruConsentGDPRStatusNotRequired");
|
|
|
|
|
msg = @"GuruConsentGDPRStatusNotRequired";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GuruConsentGDPRStatusObtained:
|
|
|
|
|
NSLog(@"--- GuruConsentGDPRStatusObtained");
|
|
|
|
|
msg = @"GuruConsentGDPRStatusObtained";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
NSLog(@"GDPR 结果: %ld", (long)status);
|
|
|
|
|
|
|
|
|
|
// 发送数据
|
|
|
|
|
[U3DConsent sendMessage: [U3DConsent buildDataString: (int)status andMessage:msg]];
|
|
|
|
|
|
|
|
|
|
} failure:^(NSError * _Nonnull error) {
|
|
|
|
|
NSLog(@"失败: %@", error);
|
|
|
|
|
[U3DConsent sendMessage: [U3DConsent buildDataString: -100 andMessage:@"request failed"]];
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+(char*) finalChar: (NSString *) string
|
|
|
|
|
{
|
|
|
|
|
const char *tmpChar = [string cStringUsingEncoding:NSASCIIStringEncoding];
|
|
|
|
|
|
|
|
|
|
if (string == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
char* res = (char*)malloc(strlen(tmpChar) + 1);
|
|
|
|
|
strcpy(res, tmpChar);
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构建数据
|
|
|
|
|
+(NSString *) buildDataString: (int)status andMessage: (NSString *)msg{
|
|
|
|
|
|
|
|
|
|
NSString *jsonString = [NSString stringWithFormat: @"{\"action\":\"gdpr\",\"data\":{\"status\":%d,\"msg\":\"%@\"}}", status, msg];
|
|
|
|
|
|
|
|
|
|
// NSDictionary *dict = @{@"action" : @"gdpr"};
|
|
|
|
|
// [dict setValue:@{@"status" : [NSString stringWithFormat:@"%d",status], @"msg": msg} forKey:@"data"];
|
|
|
|
|
//
|
|
|
|
|
// NSData *data = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
|
|
|
|
|
// NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
|
|
|
|
|
|
|
|
|
return jsonString;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 向Unity发送数据
|
|
|
|
|
+(void) sendMessage: (NSString *)msg
|
|
|
|
|
{
|
2024-02-23 17:50:04 +00:00
|
|
|
// NSLog(@"--- unityInitSDK222: %@:%@", gameobjectName, callbackName);
|
2023-12-26 04:22:19 +00:00
|
|
|
if(gameobjectName != nil && callbackName != nil){
|
|
|
|
|
char *t1 = [U3DConsent finalChar: gameobjectName];
|
|
|
|
|
char *t2 = [U3DConsent finalChar: callbackName];
|
|
|
|
|
char *t3 = [U3DConsent finalChar: msg];
|
|
|
|
|
|
|
|
|
|
UnitySendMessage(t1, t2, t3);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
|
|
// 请求GDPR
|
|
|
|
|
void unityRequestGDPR(const char * value, int debugGeo){
|
|
|
|
|
[U3DConsent requestGDPR:[NSString stringWithUTF8String:value] :debugGeo];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 初始化SDK
|
|
|
|
|
void unityInitSDK(const char *gameobject, const char *method){
|
2024-02-23 17:50:04 +00:00
|
|
|
// NSLog(@"--- unityInitSDK111: %s:%s", gameobject, method);
|
2023-12-26 04:22:19 +00:00
|
|
|
gameobjectName = [NSString stringWithUTF8String:gameobject];
|
|
|
|
|
callbackName = [NSString stringWithUTF8String:method];
|
|
|
|
|
}
|
2024-02-23 03:37:53 +00:00
|
|
|
|
2024-02-23 17:50:04 +00:00
|
|
|
// 获取 TFC 提交状态码
|
|
|
|
|
char* unityGetTCFValue(){
|
2024-02-23 03:37:53 +00:00
|
|
|
NSString *purposeConsents = [NSUserDefaults.standardUserDefaults
|
|
|
|
|
stringForKey:@"IABTCF_PurposeConsents"];
|
2024-02-23 17:50:04 +00:00
|
|
|
return [U3DConsent finalChar: purposeConsents];
|
2024-02-23 03:37:53 +00:00
|
|
|
}
|
2023-12-26 04:22:19 +00:00
|
|
|
|
|
|
|
|
}
|