Skip to content

Commit

Permalink
implement apple open delete account
Browse files Browse the repository at this point in the history
  • Loading branch information
irov committed Nov 14, 2024
1 parent dd68f1f commit c36d325
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Applications/SDLApplication/SDLUIApplicationDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ - (void)postFinishLaunch {

SDL_iPhoneSetEventPump( SDL_FALSE );

[iOSDetail alertWithTitle:@"Failed..."
[iOSDetail showOkAlertWithTitle:@"Failed..."
message:@"Mengine bootstraped application"
ok:^{
::exit( EXIT_FAILURE );
Expand All @@ -321,7 +321,7 @@ - (void)postFinishLaunch {

SDL_iPhoneSetEventPump( SDL_FALSE );

[iOSDetail alertWithTitle:@"Failed..."
[iOSDetail showOkAlertWithTitle:@"Failed..."
message:@"Mengine initialized application"
ok:^{
::exit( EXIT_FAILURE );
Expand Down
2 changes: 2 additions & 0 deletions src/Environment/Apple/AppleUserDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
+ (BOOL)hasKey:(NSString *)key;
+ (BOOL)removeKey:(NSString *)key;

+ (BOOL)clear;

@end
15 changes: 15 additions & 0 deletions src/Environment/Apple/AppleUserDefaults.mm
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,19 @@ + (BOOL)removeKey:(NSString *)key {
return YES;
}

+ (BOOL)clear {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

if (defaults == nil) {
return NO;
}

NSString * appDomain = [[NSBundle mainBundle] bundleIdentifier];

[defaults removePersistentDomainForName:appDomain];
[defaults synchronize];

return YES;
}

@end
1 change: 1 addition & 0 deletions src/Environment/iOS/iOSApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- (BOOL)didFinishLaunchingWithOptions:(nullable NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions;

- (void)setSessionId:(NSString * _Nonnull)sessionId;
- (void)removeSessionData;

- (NSString * _Nonnull)getInstallKey;
- (NSInteger)getInstallTimestamp;
Expand Down
6 changes: 6 additions & 0 deletions src/Environment/iOS/iOSApplication.mm
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ - (void)setSessionId:(NSString * _Nonnull)sessionId {
[iOSDetail setSessionId:param];
}

- (void)removeSessionData {
[AppleUserDefaults clear];

[iOSDetail removeSessionData];
}

- (NSString * _Nonnull)getInstallKey {
return self.m_installKey;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Environment/iOS/iOSDetail.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
+ (void)log:(iOSLogRecordParam *)record;
+ (NSString *)pathForTemporaryFileWithPrefix:(NSString *)prefix ext:(NSString *)ext;

+ (void)alertWithTitle:(NSString *)title
+ (void)showOkAlertWithTitle:(NSString *)title
message:(NSString *)message
ok:(void (^)(void) _Nonnull)ok;
+ (void)alertWithViewController:(UIViewController *)viewController
+ (void)showOkAlertWithViewController:(UIViewController *)viewController
title:(NSString *)title
message:(NSString *)message
ok:(void (^)(void))ok;
Expand Down
20 changes: 14 additions & 6 deletions src/Environment/iOS/iOSDetail.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#import "iOSDetail.h"

#include "Kernel/ThreadHelper.h"

#import <AdSupport/ASIdentifierManager.h>

@implementation iOSDetail
Expand Down Expand Up @@ -161,16 +163,16 @@ + (NSString *)pathForTemporaryFileWithPrefix:(NSString *)prefix ext:(NSString *)
return result;
}

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

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

+ (void)alertWithViewController:(UIViewController *)viewController
+ (void)showOkAlertWithViewController:(UIViewController *)viewController
title:(NSString *)title
message:(NSString *)message
ok:(void (^)(void) _Nonnull)ok {
Expand All @@ -180,7 +182,9 @@ + (void)alertWithViewController:(UIViewController *)viewController

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

[alertController addAction:okAction];
Expand Down Expand Up @@ -221,13 +225,17 @@ + (void)showAreYouSureAlertDialogWithContext:(UIViewController *)viewController
UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"YES"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
yes();
Mengine::Helper::dispatchMainThreadEvent([yes]() {
yes();
});
}];

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

[alert addAction:cancelAction];
Expand Down
17 changes: 15 additions & 2 deletions src/Platforms/iOSPlatform/iOSPlatformService.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
#include "Interface/ThreadServiceInterface.h"
#include "Interface/EnvironmentServiceInterface.h"
#include "Interface/iOSKernelServiceInterface.h"
#include "Interface/AccountServiceInterface.h"

#include "Environment/iOS/iOSDetail.h"
#import "Environment/iOS/iOSApplication.h"
#import "Environment/iOS/iOSDetail.h"

#include "Kernel/FilePath.h"
#include "Kernel/PathHelper.h"
Expand Down Expand Up @@ -900,7 +902,7 @@ static void SDL_LogOutputFunction( void * userdata, int category, SDL_LogPriorit

if( [MFMailComposeViewController canSendMail] == NO )
{
[iOSDetail alertWithViewController:viewController
[iOSDetail showOkAlertWithViewController:viewController
title:@"Yikes."
message:@"Log into your mailbox using the standard Mail app"
ok:^{}];
Expand Down Expand Up @@ -941,6 +943,17 @@ static void SDL_LogOutputFunction( void * userdata, int category, SDL_LogPriorit
yes:^() {
LOGGER_MESSAGE("delete account [YES]");

[[iOSApplication sharedInstance] removeSessionData];

ACCOUNT_SERVICE()
->deleteCurrentAccount();

[iOSDetail showOkAlertWithTitle:@"Account Deleted"
message:@"Account data has been deleted. The application will now close."
ok:^() {
APPLICATION_SERVICE()
->quit();
}];
}
cancel: ^() {
LOGGER_MESSAGE("delete account [CANCEL]");
Expand Down

0 comments on commit c36d325

Please sign in to comment.