Skip to content

Commit

Permalink
add iOSPluginSessionIdDelegateInterface
Browse files Browse the repository at this point in the history
wip ios open delete account
  • Loading branch information
irov committed Nov 14, 2024
1 parent e0dcab9 commit dd68f1f
Show file tree
Hide file tree
Showing 25 changed files with 240 additions and 61 deletions.
1 change: 1 addition & 0 deletions src/Applications/SDLApplication/SDLUIApplicationDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

@property (nonatomic, strong) NSMutableArray<iOSPluginApplicationDelegateInterface> * m_pluginApplicationDelegates;
@property (nonatomic, strong) NSMutableArray<iOSPluginLoggerDelegateInterface> * m_pluginLoggerDelegates;
@property (nonatomic, strong) NSMutableArray<iOSPluginSessionIdDelegateInterface> * m_pluginSessionIdDelegates;
@property (nonatomic, strong) NSMutableArray<iOSPluginAdRevenueDelegateInterface> * m_pluginAdRevenueDelegates;
@property (nonatomic, strong) NSMutableArray<iOSPluginTransparencyConsentDelegateInterface> * m_pluginTransparencyConsentDelegates;

Expand Down
33 changes: 29 additions & 4 deletions src/Applications/SDLApplication/SDLUIApplicationDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ - (id)init {

self.m_pluginApplicationDelegates = [NSMutableArray<iOSPluginApplicationDelegateInterface> array];
self.m_pluginLoggerDelegates = [NSMutableArray<iOSPluginLoggerDelegateInterface> array];
self.m_pluginSessionIdDelegates = [NSMutableArray<iOSPluginSessionIdDelegateInterface> array];
self.m_pluginAdRevenueDelegates = [NSMutableArray<iOSPluginAdRevenueDelegateInterface> array];
self.m_pluginTransparencyConsentDelegates = [NSMutableArray<iOSPluginTransparencyConsentDelegateInterface> array];

Expand All @@ -44,6 +45,10 @@ - (id)init {
if ([delegate conformsToProtocol:@protocol(iOSPluginLoggerDelegateInterface)] == YES) {
[self.m_pluginLoggerDelegates addObject:delegate];
}

if ([delegate conformsToProtocol:@protocol(iOSPluginSessionIdDelegateInterface)] == YES) {
[self.m_pluginSessionIdDelegates addObject:delegate];
}

if ([delegate conformsToProtocol:@protocol(iOSPluginAdRevenueDelegateInterface)] == YES) {
[self.m_pluginAdRevenueDelegates addObject:delegate];
Expand All @@ -67,6 +72,10 @@ - (id)init {
return self.m_pluginLoggerDelegates;
}

- (NSArray<iOSPluginSessionIdDelegateInterface> *)getPluginSessionIdDelegates {
return self.m_pluginSessionIdDelegates;
}

- (NSArray<iOSPluginAdRevenueDelegateInterface> *)getPluginAdRevenueDelegates {
return self.m_pluginAdRevenueDelegates;
}
Expand Down Expand Up @@ -104,6 +113,18 @@ - (void)log:(iOSLogRecordParam *)record {
}
}

- (void)setSessionId:(iOSSessionIdParam *)sessionId {
for (NSObject<iOSPluginSessionIdDelegateInterface> * delegate in self.m_pluginSessionIdDelegates) {
[delegate onSessionId:sessionId];
}
}

- (void)removeSessionData {
for (NSObject<iOSPluginSessionIdDelegateInterface> * delegate in self.m_pluginSessionIdDelegates) {
[delegate onRemoveSessionData];
}
}

- (void)eventAdRevenue:(iOSAdRevenueParam *)revenue {
for (NSObject<iOSPluginAdRevenueDelegateInterface> * delegate in self.m_pluginAdRevenueDelegates) {
[delegate onAdRevenue:revenue];
Expand Down Expand Up @@ -282,8 +303,10 @@ - (void)postFinishLaunch {

SDL_iPhoneSetEventPump( SDL_FALSE );

[iOSDetail alertWithTitle:@"Failed..." message:@"Mengine bootstraped application" callback:^{
::exit( EXIT_SUCCESS );
[iOSDetail alertWithTitle:@"Failed..."
message:@"Mengine bootstraped application"
ok:^{
::exit( EXIT_FAILURE );
}];

return;
Expand All @@ -298,8 +321,10 @@ - (void)postFinishLaunch {

SDL_iPhoneSetEventPump( SDL_FALSE );

[iOSDetail alertWithTitle:@"Failed..." message:@"Mengine initialized application" callback:^{
::exit( EXIT_SUCCESS );
[iOSDetail alertWithTitle:@"Failed..."
message:@"Mengine initialized application"
ok:^{
::exit( EXIT_FAILURE );
}];

return;
Expand Down
2 changes: 1 addition & 1 deletion src/Environment/Apple/AppleDetail.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ + (NSIDMessage)NSIdToString:(id _Nonnull) _value {
+ (NSErrorMessage)getMessageFromNSError:(NSError *) _error {
NSString * message = [NSString stringWithFormat:@"[Error %ld Description: %@ Failure reason: %@ Recovery suggestion: %@"
, [_error code]
, [_error localizedDescription]
, [_error description]
, [_error localizedFailureReason]
, [_error localizedRecoverySuggestion]
];
Expand Down
1 change: 0 additions & 1 deletion src/Environment/Apple/AppleEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
@property (class, nonatomic, readonly) AppleEvent * EVENT_GDPR_PASS;
@property (class, nonatomic, readonly) AppleEvent * EVENT_PUSH_TOKEN;
@property (class, nonatomic, readonly) AppleEvent * EVENT_ADVERTISING_ID;
@property (class, nonatomic, readonly) AppleEvent * EVENT_SESSION_ID;
@property (class, nonatomic, readonly) AppleEvent * EVENT_REMOTE_CONFIG_FETCH;

@property (nonatomic, strong, readonly) NSString * name;
Expand Down
1 change: 0 additions & 1 deletion src/Environment/Apple/AppleEvent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ + (AppleEvent *)NAME {\
DECLARE_APPLE_EVENT(EVENT_GDPR_PASS)
DECLARE_APPLE_EVENT(EVENT_PUSH_TOKEN)
DECLARE_APPLE_EVENT(EVENT_ADVERTISING_ID)
DECLARE_APPLE_EVENT(EVENT_SESSION_ID)
DECLARE_APPLE_EVENT(EVENT_REMOTE_CONFIG_FETCH)

- (instancetype)initWithName:(NSString *)name {
Expand Down
4 changes: 4 additions & 0 deletions src/Environment/iOS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ src
iOSTransparencyConsentParam.h
iOSTransparencyConsentParam.mm

iOSSessionIdParam.h
iOSSessionIdParam.mm

iOSAdRevenueParam.h
iOSAdRevenueParam.mm

Expand All @@ -27,6 +30,7 @@ src

iOSUIMainApplicationDelegateInterface.h

iOSPluginSessionIdDelegateInterface.h
iOSPluginAdRevenueDelegateInterface.h
iOSPluginApplicationDelegateInterface.h
iOSPluginTransparencyConsentDelegateInterface.h
Expand Down
5 changes: 4 additions & 1 deletion src/Environment/iOS/iOSApplication.mm
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ - (void)setSessionId:(NSString * _Nonnull)sessionId {

[AppleUserDefaults setStringForKey:@"mengine.session_id" value:self.m_sessionId];

[iOSDetail eventNotify:AppleEvent.EVENT_SESSION_ID args:@[self.m_sessionId]];
iOSSessionIdParam * param = [iOSSessionIdParam alloc];
param.SESSION_ID = self.m_sessionId;

[iOSDetail setSessionId:param];
}

- (NSString * _Nonnull)getInstallKey {
Expand Down
23 changes: 21 additions & 2 deletions src/Environment/iOS/iOSDetail.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,31 @@
+ (id)getUIProxyApplicationDelegate:(Class)delegateClass;

+ (void)eventNotify:(AppleEvent *)event args:(NSArray<id> *)args;
+ (void)setSessionId:(iOSSessionIdParam *)sessionId;
+ (void)removeSessionData;
+ (void)adRevenue:(iOSAdRevenueParam *)revenue;
+ (void)transparencyConsent:(iOSTransparencyConsentParam *)consent;
+ (void)log:(iOSLogRecordParam *)record;
+ (NSString *)pathForTemporaryFileWithPrefix:(NSString *)prefix ext:(NSString *)ext;

+ (void)alertWithTitle:(NSString *)title message:(NSString *)message callback:(void (^)(void))callback;
+ (void)alertWithViewController:(UIViewController *)viewController title:(NSString *)title message:(NSString *)message callback:(void (^)(void))callback;
+ (void)alertWithTitle:(NSString *)title
message:(NSString *)message
ok:(void (^)(void) _Nonnull)ok;
+ (void)alertWithViewController:(UIViewController *)viewController
title:(NSString *)title
message:(NSString *)message
ok:(void (^)(void))ok;

+ (void)showAreYouSureAlertDialogWithTitle:(NSString *)title
message:(NSString *)message
delay:(NSTimeInterval)delayMillis
yes:(void (^)(void) _Nonnull)yes
cancel:(void (^)(void) _Nonnull)cancel;
+ (void)showAreYouSureAlertDialogWithContext:(UIViewController *)viewController
title:(NSString *)title
message:(NSString *)message
delay:(NSTimeInterval)delayMillis
yes:(void (^)(void) _Nonnull)yes
cancel:(void (^)(void) _Nonnull)cancel;

@end
105 changes: 92 additions & 13 deletions src/Environment/iOS/iOSDetail.mm
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ + (UIWindow *)getRootWindow {
}

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

return view;
}

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

return viewController;
Expand Down Expand Up @@ -102,31 +102,47 @@ + (id)getUIProxyApplicationDelegate:(Class)delegateClass {

+ (void)eventNotify:(AppleEvent *)event args:(NSArray<id> *)args {
[iOSDetail addMainQueueOperation:^{
NSObject<iOSUIMainApplicationDelegateInterface> *delegate = [self getUIMainApplicationDelegate];
NSObject<iOSUIMainApplicationDelegateInterface> *delegate = [iOSDetail getUIMainApplicationDelegate];

[delegate notify:event arrayArgs:args];
}];
}

+ (void)setSessionId:(iOSSessionIdParam *)sessionId {
[iOSDetail addMainQueueOperation:^{
NSObject<iOSUIMainApplicationDelegateInterface> *delegate = [iOSDetail getUIMainApplicationDelegate];

[delegate setSessionId:sessionId];
}];
}

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

[delegate removeSessionData];
}];
}

+ (void)adRevenue:(iOSAdRevenueParam *)revenue {
[iOSDetail addMainQueueOperation:^{
NSObject<iOSUIMainApplicationDelegateInterface> *delegate = [self getUIMainApplicationDelegate];
NSObject<iOSUIMainApplicationDelegateInterface> *delegate = [iOSDetail getUIMainApplicationDelegate];

[delegate eventAdRevenue:revenue];
}];
}

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

[delegate eventTransparencyConsent:consent];
}];
}

+ (void)log:(iOSLogRecordParam *)record {
[iOSDetail addMainQueueOperation:^{
NSObject<iOSUIMainApplicationDelegateInterface> *delegate = [self getUIMainApplicationDelegate];
NSObject<iOSUIMainApplicationDelegateInterface> *delegate = [iOSDetail getUIMainApplicationDelegate];

[delegate log:record];
}];
Expand All @@ -145,21 +161,26 @@ + (NSString *)pathForTemporaryFileWithPrefix:(NSString *)prefix ext:(NSString *)
return result;
}

+ (void)alertWithTitle:(NSString *)title message:(NSString *)message callback:(void (^)(void))callback {
UIViewController *rootViewController = [self getRootViewController];
[self alertWithViewController:rootViewController title:title message:message callback:callback];
+ (void)alertWithTitle:(NSString *)title message:(NSString *)message ok:(void (^)(void) _Nonnull)ok {
UIViewController * viewController = [iOSDetail getRootViewController];

[iOSDetail alertWithViewController:viewController
title:title
message:message
ok:ok];
}

+ (void)alertWithViewController:(UIViewController *)viewController title:(NSString *)title message:(NSString *)message callback:(void (^)(void))callback {
+ (void)alertWithViewController:(UIViewController *)viewController
title:(NSString *)title
message:(NSString *)message
ok:(void (^)(void) _Nonnull)ok {
if (viewController == nil) {
return;
}

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
if (callback) {
callback();
}
ok();
}];

[alertController addAction:okAction];
Expand All @@ -169,4 +190,62 @@ + (void)alertWithViewController:(UIViewController *)viewController title:(NSStri
});
}

+ (void)showAreYouSureAlertDialogWithTitle:(NSString *)title
message:(NSString *)message
delay:(NSTimeInterval)delayMillis
yes:(void (^)(void) _Nonnull)yes
cancel:(void (^)(void) _Nonnull)cancel {
UIViewController * viewController = [iOSDetail getRootViewController];

[iOSDetail showAreYouSureAlertDialogWithContext:viewController
title:title
message:message
delay:delayMillis
yes:yes
cancel:cancel];
}

+ (void)showAreYouSureAlertDialogWithContext:(UIViewController *)viewController
title:(NSString *)title
message:(NSString *)message
delay:(NSTimeInterval)delayMillis
yes:(void (^)(void) _Nonnull)yes
cancel:(void (^)(void) _Nonnull)cancel {
NSString * areYouSureText = @"\n\nAre you sure?";
NSString * fullMessage = [message stringByAppendingString:areYouSureText];

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

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

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"CANCEL"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * _Nonnull action) {
cancel();
}];

[alert addAction:cancelAction];
[alert addAction:yesAction];

if (delayMillis > 0) {
yesAction.enabled = NO;
yesAction.accessibilityHint = @"Disabled temporarily";

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayMillis * NSEC_PER_MSEC)), dispatch_get_main_queue(), ^{
yesAction.enabled = YES;
yesAction.accessibilityHint = nil;
});
}

dispatch_async(dispatch_get_main_queue(), ^{
[viewController presentViewController:alert animated:YES completion:nil];
});
}

@end
10 changes: 10 additions & 0 deletions src/Environment/iOS/iOSPluginSessionIdDelegateInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "Config/Config.h"

#import "Environment/iOS/iOSSessionIdParam.h"

@protocol iOSPluginSessionIdDelegateInterface <NSObject>

- (void)onSessionId:(iOSSessionIdParam *)session;
- (void)onRemoveSessionData;

@end
11 changes: 11 additions & 0 deletions src/Environment/iOS/iOSSessionIdParam.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "Config/Config.h"

#import <Foundation/Foundation.h>

@interface iOSSessionIdParam : NSObject

@property (nonatomic, strong) NSString * _Nonnull SESSION_ID;

@end
5 changes: 5 additions & 0 deletions src/Environment/iOS/iOSSessionIdParam.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import "iOSSessionIdParam.h"

@implementation iOSSessionIdParam

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

#import "Environment/iOS/iOSPluginApplicationDelegateInterface.h"
#import "Environment/iOS/iOSPluginLoggerDelegateInterface.h"
#import "Environment/iOS/iOSPluginSessionIdDelegateInterface.h"
#import "Environment/iOS/iOSPluginAdRevenueDelegateInterface.h"
#import "Environment/iOS/iOSPluginTransparencyConsentDelegateInterface.h"

Expand All @@ -11,6 +12,7 @@

- (NSArray<iOSPluginApplicationDelegateInterface> *)getPluginApplicationDelegates;
- (NSArray<iOSPluginLoggerDelegateInterface> *)getPluginLoggerDelegates;
- (NSArray<iOSPluginSessionIdDelegateInterface> *)getPluginSessionIdDelegates;
- (NSArray<iOSPluginAdRevenueDelegateInterface> *)getPluginAdRevenueDelegates;
- (NSArray<iOSPluginTransparencyConsentDelegateInterface> *)getPluginTransparencyConsentDelegates;

Expand All @@ -19,6 +21,8 @@

- (void)log:(iOSLogRecordParam *)record;

- (void)setSessionId:(iOSSessionIdParam *)sessionId;
- (void)removeSessionData;
- (void)eventAdRevenue:(iOSAdRevenueParam *)revenue;
- (void)eventTransparencyConsent:(iOSTransparencyConsentParam *)consent;

Expand Down
Loading

0 comments on commit dd68f1f

Please sign in to comment.