Skip to content

Commit

Permalink
add iOS isAppTrackingTransparencyAllowed
Browse files Browse the repository at this point in the history
fix apple AppleAppTrackingService
  • Loading branch information
irov committed Dec 17, 2024
1 parent af78bea commit b26b9b7
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 36 deletions.
1 change: 1 addition & 0 deletions src/Environment/iOS/iOSDetail.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

+ (NSString *)getDeviceId;
+ (NSString *)getDeviceName;
+ (BOOL)isAppTrackingTransparencyAllowed;
+ (NSString *)getIDFA;
+ (BOOL)isValidIDFA;

Expand Down
40 changes: 27 additions & 13 deletions src/Environment/iOS/iOSDetail.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ + (NSString *)getDeviceName {
return deviceName;
}

+ (BOOL)isAppTrackingTransparencyAllowed {
if (@available(iOS 14.5, *)) {
if (ATTrackingManager.trackingAuthorizationStatus == ATTrackingManagerAuthorizationStatusAuthorized) {
return YES;
}
} else {
if ([iOSDetail isValidIDFA] == YES) {
return YES;
}
}

return NO;
}

+ (NSString *)getIDFA {
NSUUID * idfa_uuid = [iOSDetail getAdIdentifier];

Expand Down Expand Up @@ -50,29 +64,29 @@ + (BOOL)isValidIDFA {
}

+ (UIWindow *)getRootWindow {
UIApplication *application = [UIApplication sharedApplication];
UIApplication * application = [UIApplication sharedApplication];
id<UIApplicationDelegate> delegate = application.delegate;
UIWindow *window = delegate.window;
UIWindow * window = delegate.window;

return window;
}

+ (UIView *)getRootView {
UIWindow *window = [iOSDetail getRootWindow];
UIView *view = [window.subviews objectAtIndex:0];
UIWindow * window = [iOSDetail getRootWindow];
UIView * view = [window.subviews objectAtIndex:0];

return view;
}

+ (UIViewController *)getRootViewController {
UIWindow *window = [iOSDetail getRootWindow];
UIWindow * window = [iOSDetail getRootWindow];
UIViewController *viewController = window.rootViewController;

return viewController;
}

+ (NSUUID *)getAdIdentifier {
NSUUID *idfa_uuid = [[ASIdentifierManager sharedManager] advertisingIdentifier];
NSUUID * idfa_uuid = [[ASIdentifierManager sharedManager] advertisingIdentifier];

return idfa_uuid;
}
Expand Down Expand Up @@ -136,7 +150,7 @@ + (void)adRevenue:(iOSAdRevenueParam *)revenue {

+ (void)transparencyConsent:(iOSTransparencyConsentParam *)consent {
[iOSDetail addMainQueueOperation:^{
NSObject<iOSUIMainApplicationDelegateInterface> *delegate = [iOSDetail getUIMainApplicationDelegate];
NSObject<iOSUIMainApplicationDelegateInterface> * delegate = [iOSDetail getUIMainApplicationDelegate];

[delegate eventTransparencyConsent:consent];
}];
Expand All @@ -151,7 +165,7 @@ + (void)log:(iOSLogRecordParam *)record {
}

+ (NSString *)pathForTemporaryFileWithPrefix:(NSString *)prefix ext:(NSString *)ext {
NSString *result;
NSString * result;
CFUUIDRef uuid = CFUUIDCreate(NULL);
CFStringRef uuidStr = CFUUIDCreateString(NULL, uuid);

Expand Down Expand Up @@ -180,8 +194,8 @@ + (void)showOkAlertWithViewController:(UIViewController *)viewController
return;
}

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
UIAlertController * alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction * okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
Mengine::Helper::dispatchMainThreadEvent([ok]() {
ok();
});
Expand Down Expand Up @@ -218,19 +232,19 @@ + (void)showAreYouSureAlertDialogWithContext:(UIViewController *)viewController
NSString * areYouSureText = @"\n\nAre you sure?";
NSString * fullMessage = [message stringByAppendingString:areYouSureText];

UIAlertController *alert = [UIAlertController alertControllerWithTitle:title
UIAlertController * alert = [UIAlertController alertControllerWithTitle:title
message:fullMessage
preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"YES"
UIAlertAction * yesAction = [UIAlertAction actionWithTitle:@"YES"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
Mengine::Helper::dispatchMainThreadEvent([yes]() {
yes();
});
}];

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"CANCEL"
UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"CANCEL"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * _Nonnull action) {
Mengine::Helper::dispatchMainThreadEvent([cancel]() {
Expand Down
59 changes: 37 additions & 22 deletions src/Plugins/AppleAppTrackingPlugin/AppleAppTrackingService.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//////////////////////////////////////////////////////////////////////////
AppleAppTrackingService::AppleAppTrackingService()
: m_status( EAATA_NONE )
, m_idfa( nil )
, m_idfa( @"00000000-0000-0000-0000-000000000000" )
{
}
//////////////////////////////////////////////////////////////////////////
Expand All @@ -28,19 +28,19 @@
//////////////////////////////////////////////////////////////////////////
bool AppleAppTrackingService::_initializeService()
{
m_idfa = @"00000000-0000-0000-0000-000000000000";
//Empty

return true;
}
//////////////////////////////////////////////////////////////////////////
void AppleAppTrackingService::_finalizeService()
{
m_idfa = nil;
//Empty
}
//////////////////////////////////////////////////////////////////////////
void AppleAppTrackingService::authorization( const LambdaAuthorizationResponse & _response )
{
if(@available(iOS 14.0, *))
if( @available(iOS 14.0, *) )
{
LambdaAuthorizationResponse copy_response = _response;

Expand Down Expand Up @@ -76,17 +76,17 @@
copy_response( status_copy, idfa_str );
});
}];
}
else
{
m_status = EAATA_AUTHORIZED;

this->makeIDFA_();

const Char * idfa_str = [m_idfa UTF8String];

_response( m_status, idfa_str );
return;
}

m_status = EAATA_AUTHORIZED;

this->makeIDFA_();

const Char * idfa_str = [m_idfa UTF8String];

_response( m_status, idfa_str );
}
//////////////////////////////////////////////////////////////////////////
void AppleAppTrackingService::getIDFA( EAppleAppTrackingAuthorization * const _status, Char * const _idfa ) const
Expand Down Expand Up @@ -114,21 +114,36 @@
//////////////////////////////////////////////////////////////////////////
bool AppleAppTrackingService::isTrackingAllowed() const
{
if(@available(iOS 14.5, *))
if( @available(iOS 14.5, *) )
{
if( ATTrackingManager.trackingAuthorizationStatus == ATTrackingManagerAuthorizationStatusDenied )
switch( ATTrackingManager.trackingAuthorizationStatus )
{
return false;
case ATTrackingManagerAuthorizationStatusAuthorized:
{
return true;
}break;
case ATTrackingManagerAuthorizationStatusDenied:
{
return false;
}break;
case ATTrackingManagerAuthorizationStatusNotDetermined:
{
return false;
}break;
case ATTrackingManagerAuthorizationStatusRestricted:
{
return false;
}break;
}

return false;
}
else

if( [iOSDetail isValidIDFA] == NO )
{
if( [iOSDetail isValidIDFA] == NO )
{
return false;
}
return false;
}

return true;
}
//////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/Systems/POSIXThreadSystem/POSIXThreadSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ namespace Mengine
//////////////////////////////////////////////////////////////////////////
ThreadId POSIXThreadSystem::getCurrentThreadId() const
{
pthread_t threadId = pthread_self();
pthread_t threadId = ::pthread_self();

return (ThreadId)threadId;
}
Expand Down

0 comments on commit b26b9b7

Please sign in to comment.