Skip to content

Commit

Permalink
Add GDPR allow for iOS Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
irov committed Aug 27, 2023
1 parent f0cea39 commit 1bf462b
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 37 deletions.
1 change: 1 addition & 0 deletions src/Environment/iOS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ src
iOSDetail.h
iOSDetail.mm

UIMainApplicationDelegateInterface.h
UIProxyApplicationDelegateInterface.h
)

Expand Down
7 changes: 6 additions & 1 deletion src/Environment/iOS/UIMainApplicationDelegateInterface.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#include "Config/Config.h"

#import "Environment/iOS/UIProxyApplicationDelegateInterface.h"

#import <Foundation/Foundation.h>

@protocol UIMainApplicationDelegateInterface <NSObject>

- (void)notify:(NSString *)id args:(NSArray *)args;
- (NSArray<UIProxyApplicationDelegateInterface> *)getPluginDelegates;

- (void)notify:(NSString *)name args:(id)firstArg, ... NS_REQUIRES_NIL_TERMINATION;
- (void)notify:(NSString *)name arrayArgs:(NSArray<id> *)args;

@end
2 changes: 2 additions & 0 deletions src/Environment/iOS/UIProxyApplicationDelegateInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

@optional

- (void)event:(NSString *)name args:(NSArray *)args;

#pragma mark - UISceneSession lifecycle

- (void)applicationWillResignActive:(UIApplication *)application;
Expand Down
4 changes: 4 additions & 0 deletions src/Environment/iOS/iOSDetail.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "Config/Config.h"

#import "Environment/iOS/UIProxyApplicationDelegateInterface.h"

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

Expand All @@ -11,5 +13,7 @@ namespace Mengine
{
UIViewController * iOSGetRootViewController();
NSUUID * iOSGetAdIdentifier();
id iOSGetUIProxyApplicationDelegate( Class delegateClass );
void iOSPluginApplicationDelegateEventNotify( NSString * name, id firstArg, ... );
}
}
35 changes: 35 additions & 0 deletions src/Environment/iOS/iOSDetail.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "iOSDetail.h"

#import "Environment/iOS/UIMainApplicationDelegateInterface.h"

#import <AdSupport/ASIdentifierManager.h>

namespace Mengine
Expand All @@ -23,5 +25,38 @@
return idfa_uuid;
}
//////////////////////////////////////////////////////////////////////////
id iOSGetUIProxyApplicationDelegate( Class delegateClass )
{
NSObject<UIMainApplicationDelegateInterface> * delegate = (NSObject<UIMainApplicationDelegateInterface> *)[[UIApplication sharedApplication] delegate];

NSArray<UIProxyApplicationDelegateInterface> * pluginDelegates = [delegate getPluginDelegates];

for( NSObject<UIProxyApplicationDelegateInterface> * delegate : pluginDelegates ) {
if( [delegate isMemberOfClass:delegateClass] == YES ) {
return delegate;
}
}

return nil;
}
//////////////////////////////////////////////////////////////////////////
void iOSPluginApplicationDelegateEventNotify( NSString * name, id firstArg, ... )
{
NSObject<UIMainApplicationDelegateInterface> * delegate = (NSObject<UIMainApplicationDelegateInterface> *)[[UIApplication sharedApplication] delegate];

va_list args;
va_start(args, firstArg);

NSMutableArray * send_args = [[NSMutableArray alloc] init];

for( NSString *arg = firstArg; arg != nil; arg = va_arg(args, NSString*) ) {
[send_args addObject:firstArg];
}

va_end(args);

[delegate notify:name arrayArgs:send_args];
}
//////////////////////////////////////////////////////////////////////////
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

@interface AppleGeneralDataProtectionRegulationApplicationDelegate : NSObject<UIProxyApplicationDelegateInterface>

- (void) setGDPRPass:(BOOL) passGDPR;
- (BOOL) isGDPRPass;

@end
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
#import "AppleGeneralDataProtectionRegulationApplicationDelegate.h"

#include "Environment/Apple/AppleUserDefaults.h"
#import "Environment/iOS/iOSDetail.h"
#import "Environment/Apple/AppleUserDefaults.h"

@implementation AppleGeneralDataProtectionRegulationApplicationDelegate

- (void)setGDPRPass:(BOOL)passGDPR {
Mengine::Helper::AppleSetUserDefaultsBoolean( "mengine.gdpr.pass", passGDPR );

Mengine::Helper::iOSPluginApplicationDelegateEventNotify( @"NOTIFICATION_GDPR_PASS", @(passGDPR), nil );
}

- (BOOL)isGDPRPass {
bool passGDPR = Mengine::Helper::AppleGetUserDefaultsBoolean( "mengine.gdpr.pass", false );

return passGDPR;
}

#pragma mark - UIProxyApplicationDelegateInterface

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
bool passGDPR = Mengine::Helper::AppleGetUserDefaultsBoolean( "mengine.gdpr.pass", false );

Mengine::Helper::iOSPluginApplicationDelegateEventNotify( @"NOTIFICATION_GDPR_PASS", @(passGDPR), nil );

return YES;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ namespace Mengine

public:
void setGDPRPass( bool _passGDPR ) override;
bool isGDPRPass() const override;

protected:
bool m_passGDPR;
bool isGDPRPass() const override;
};
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#include "AppleGeneralDataProtectionRegulationService.h"

#include "Environment/Apple/AppleUserDefaults.h"
#import "AppleGeneralDataProtectionRegulationApplicationDelegate.h"

#import "Environment/iOS/iOSDetail.h"
#import "Environment/Apple/AppleUserDefaults.h"

#include "Kernel/Logger.h"

#import <UIKit/UIKit.h>

////////////////////////////////////////////////////////////////////////////
SERVICE_FACTORY( AppleGeneralDataProtectionRegulationService, Mengine::AppleGeneralDataProtectionRegulationService );
//////////////////////////////////////////////////////////////////////////
namespace Mengine
{
//////////////////////////////////////////////////////////////////////////
AppleGeneralDataProtectionRegulationService::AppleGeneralDataProtectionRegulationService()
: m_passGDPR(false)
{
}
//////////////////////////////////////////////////////////////////////////
Expand All @@ -21,9 +25,7 @@
/////////////////////////////////////////////////////////////////////////////
bool AppleGeneralDataProtectionRegulationService::_initializeService()
{
bool passGDPR = Helper::AppleGetUserDefaultsBoolean( "mengine.gdpr.pass", false );

m_passGDPR = passGDPR;
//Empty

return true;
}
Expand All @@ -39,14 +41,18 @@
, _passGDPR
);

Helper::AppleSetUserDefaultsBoolean( "mengine.gdpr.pass", _passGDPR );

m_passGDPR = _passGDPR;
AppleGeneralDataProtectionRegulationApplicationDelegate * delegate = Helper::iOSGetUIProxyApplicationDelegate([AppleGeneralDataProtectionRegulationApplicationDelegate class]);
[delegate setGDPRPass:(BOOL)_passGDPR];
}
//////////////////////////////////////////////////////////////////////////
bool AppleGeneralDataProtectionRegulationService::isGDPRPass() const
{
return m_passGDPR;
AppleGeneralDataProtectionRegulationApplicationDelegate * delegate = Helper::iOSGetUIProxyApplicationDelegate([AppleGeneralDataProtectionRegulationApplicationDelegate class]);

BOOL passGDPR = [delegate isGDPRPass];

return passGDPR;
}
//////////////////////////////////////////////////////////////////////////
}
18 changes: 9 additions & 9 deletions src/Plugins/AppleMARSDKPlugin/AppleMARSDKAdRewardedDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ @implementation AppleMARSDKAdRewardedDelegate

@synthesize m_service;

- (instancetype _Nonnull)initWithService: (Mengine::AppleMARSDKServiceInterface* _Nonnull)service {
- (instancetype _Nonnull)initWithService:(Mengine::AppleMARSDKServiceInterface* _Nonnull)service {
self = [super init];

self.m_service = service;
Expand All @@ -21,7 +21,7 @@ - (instancetype _Nonnull)initWithService: (Mengine::AppleMARSDKServiceInterface*

#pragma mark - MARAdRewardedDelegate

- (void) MARAdRewardedDidFailed: (MARAdErrorCode)code withMessage: (NSString *)message adDict:(NSDictionary *)adDict {
- (void) MARAdRewardedDidFailed:(MARAdErrorCode)code withMessage: (NSString *)message adDict:(NSDictionary *)adDict {
LOGGER_MESSAGE( "MARAdRewardedDidFailed code: %d message: %s adDict: %s"
, (int32_t)code
, [message UTF8String]
Expand All @@ -38,7 +38,7 @@ - (void) MARAdRewardedDidFailed: (MARAdErrorCode)code withMessage: (NSString *)m
provider->onAdRewardedDidFailed();
}

- (void) MARAdRewardedDidLoaded :(NSDictionary *)adDict {
- (void) MARAdRewardedDidLoaded:(NSDictionary *)adDict {
LOGGER_MESSAGE( "MARAdRewardedDidLoaded adDict: %s"
, [[NSString stringWithFormat:@"%@", adDict] UTF8String]
);
Expand All @@ -53,7 +53,7 @@ - (void) MARAdRewardedDidLoaded :(NSDictionary *)adDict {
provider->onAdRewardedDidLoaded();
}

- (void) MARAdRewardedDidShow :(NSDictionary *)adDict {
- (void) MARAdRewardedDidShow:(NSDictionary *)adDict {
LOGGER_MESSAGE( "MARAdRewardedDidShow adDict: %s"
, [[NSString stringWithFormat:@"%@", adDict] UTF8String]
);
Expand All @@ -68,7 +68,7 @@ - (void) MARAdRewardedDidShow :(NSDictionary *)adDict {
provider->onAdRewardedDidShow();
}

- (void) MARAdRewardedDidShowFailed :(NSDictionary *)adDict {
- (void) MARAdRewardedDidShowFailed:(NSDictionary *)adDict {
LOGGER_MESSAGE( "MARAdRewardedDidShowFailed adDict: %s"
, [[NSString stringWithFormat:@"%@", adDict] UTF8String]
);
Expand All @@ -83,7 +83,7 @@ - (void) MARAdRewardedDidShowFailed :(NSDictionary *)adDict {
provider->onAdRewardedDidShowFailed();
}

- (void) MARAdRewardedDidClicked :(NSDictionary *)adDict {
- (void) MARAdRewardedDidClicked:(NSDictionary *)adDict {
LOGGER_MESSAGE( "MARAdRewardedDidClicked adDict: %s"
, [[NSString stringWithFormat:@"%@", adDict] UTF8String]
);
Expand All @@ -98,7 +98,7 @@ - (void) MARAdRewardedDidClicked :(NSDictionary *)adDict {
provider->onAdRewardedDidClicked();
}

- (void) MARAdRewardedDidClosed :(NSDictionary *)adDict {
- (void) MARAdRewardedDidClosed:(NSDictionary *)adDict {
LOGGER_MESSAGE( "MARAdRewardedDidClosed adDict: %s"
, [[NSString stringWithFormat:@"%@", adDict] UTF8String]
);
Expand All @@ -113,7 +113,7 @@ - (void) MARAdRewardedDidClosed :(NSDictionary *)adDict {
provider->onAdRewardedDidClosed();
}

- (void) MARAdRewardedDidSkipped :(NSDictionary *)adDict {
- (void) MARAdRewardedDidSkipped:(NSDictionary *)adDict {
LOGGER_MESSAGE( "MARAdRewardedDidSkipped adDict: %s"
, [[NSString stringWithFormat:@"%@", adDict] UTF8String]
);
Expand All @@ -128,7 +128,7 @@ - (void) MARAdRewardedDidSkipped :(NSDictionary *)adDict {
provider->onAdRewardedDidSkipped();
}

- (void) MARAdRewardedDidFinished: (NSString *)itemName itemNum:(int)itemNum adDict:(NSDictionary *)adDict {
- (void) MARAdRewardedDidFinished:(NSString *)itemName itemNum:(int)itemNum adDict:(NSDictionary *)adDict {
LOGGER_MESSAGE( "MARAdRewardedDidFinished adDict: %s"
, [[NSString stringWithFormat:@"%@", adDict] UTF8String]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

@interface AppleSentryApplicationDelegate : NSObject<UIProxyApplicationDelegateInterface>

@property (assign) BOOL m_sendAllow;

@end
26 changes: 26 additions & 0 deletions src/Plugins/AppleSentryPlugin/AppleSentryApplicationDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ @implementation AppleSentryApplicationDelegate

#pragma mark - UIProxyApplicationDelegateInterface

- (instancetype _Nonnull)init {
self = [super init];

self.m_sendAllow = NO;

return self;
}

- (void)event:(NSString *)name args:(NSArray *)args {
if( [name isEqualToString:@"NOTIFICATION_GDPR_PASS"] == true ) {
BOOL passGDPR = [args[0] boolValue];

if( passGDPR == YES ) {
self.m_sendAllow = YES;
} else {
self.m_sendAllow = NO;
}
}
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString * AppleSentryPlugin_DSN = Mengine::Helper::AppleGetBundlePluginConfigString( @("MengineAppleSentryPlugin"), @("DSN"), nil );

Expand All @@ -36,11 +56,17 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
options.environment = @(ENVIRONMENT);

options.beforeSend = ^SentryEvent * _Nullable(SentryEvent * _Nonnull event) {
if( self.m_sendAllow == NO ) {
return nil;
}

return event;
};

options.beforeBreadcrumb = ^SentryBreadcrumb * _Nullable(SentryBreadcrumb * _Nonnull breadcrumb) {
if( self.m_sendAllow == NO ) {
return nil;
}

return breadcrumb;
};
Expand Down
6 changes: 4 additions & 2 deletions src/SDLApplication/SDLUIApplicationDelegate.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#import <UIKit/UIKit.h>

@interface SDLUIApplicationDelegate : NSObject<UIApplicationDelegate>
#import "Environment/iOS/UIMainApplicationDelegateInterface.h"

@property (nonatomic, strong) NSMutableArray<id> * m_pluginDelegates;
@interface SDLUIApplicationDelegate : NSObject<UIApplicationDelegate, UIMainApplicationDelegateInterface>

@property (nonatomic, strong) NSMutableArray<UIProxyApplicationDelegateInterface> * m_pluginDelegates;

@end
Loading

0 comments on commit 1bf462b

Please sign in to comment.