Skip to content

Commit

Permalink
fix apple code
Browse files Browse the repository at this point in the history
  • Loading branch information
irov committed Nov 14, 2024
1 parent c36d325 commit 434d03a
Show file tree
Hide file tree
Showing 18 changed files with 76 additions and 69 deletions.
8 changes: 2 additions & 6 deletions src/Environment/Apple/AppleDetail.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "Kernel/StaticString.h"
#include "Kernel/Params.h"
#include "Kernel/Data.h"
#include "Kernel/VectorString.h"
Expand All @@ -18,11 +17,8 @@

@interface AppleDetail : NSObject

typedef Mengine::StaticString<MENGINE_APPLE_MESSAGE_NSID> NSIDMessage;
+ (NSIDMessage)NSIdToString:(id _Nonnull) _value;

typedef Mengine::StaticString<MENGINE_APPLE_MESSAGE_NSERROR> NSErrorMessage;
+ (NSErrorMessage)getMessageFromNSError:(NSError * _Nonnull) _error;
+ (NSString * _Nonnull)NSIdToString:(id _Nonnull) _value;
+ (NSString * _Nonnull)getMessageFromNSError:(NSError * _Nonnull) _error;

+ (NSInteger)getCurrentTimeMillis;
+ (NSInteger)getSecureRandomInteger;
Expand Down
14 changes: 6 additions & 8 deletions src/Environment/Apple/AppleDetail.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@

@implementation AppleDetail

+ (NSIDMessage)NSIdToString:(id _Nonnull) _value {
const Mengine::Char * message_str = [[NSString stringWithFormat:@"%@", _value] UTF8String];
+ (NSString * _Nonnull)NSIdToString:(id _Nonnull) _value {
NSString * value_string = [NSString stringWithFormat:@"%@", _value];

return NSIDMessage( message_str );
return value_string;
}

+ (NSErrorMessage)getMessageFromNSError:(NSError *) _error {
+ (NSString * _Nonnull)getMessageFromNSError:(NSError *) _error {
NSString * message = [NSString stringWithFormat:@"[Error %ld Description: %@ Failure reason: %@ Recovery suggestion: %@"
, [_error code]
, [_error description]
, [_error localizedFailureReason]
, [_error localizedRecoverySuggestion]
];

const Mengine::Char * message_str = [message UTF8String];

return NSErrorMessage( message_str );
return message;
}

+ (NSInteger)getCurrentTimeMillis {
Expand All @@ -41,7 +39,7 @@ + (NSInteger)getSecureRandomInteger {
return randomNumber;
}

+ (NSString *)getRandomHexString:(NSInteger) _length {
+ (NSString * _Nonnull)getRandomHexString:(NSInteger) _length {
NSInteger lengthBytes = (_length + 1) / 2;
uint8_t randomBytes[lengthBytes];
if (SecRandomCopyBytes(kSecRandomDefault, lengthBytes, randomBytes) != 0) {
Expand Down
5 changes: 3 additions & 2 deletions src/Platforms/iOSPlatform/iOSPlatformService.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Interface/iOSKernelServiceInterface.h"
#include "Interface/AccountServiceInterface.h"

#import "Environment/Apple/AppleDetail.h"
#import "Environment/iOS/iOSApplication.h"
#import "Environment/iOS/iOSDetail.h"

Expand Down Expand Up @@ -144,7 +145,7 @@
if( error != nil )
{
LOGGER_ERROR( "Error creating directory: %s"
, [error.description UTF8String]
, [[AppleDetail getMessageFromNSError:error] UTF8String]
);

StdString::strncpy( _userPath, "", MENGINE_MAX_PATH );
Expand Down Expand Up @@ -943,7 +944,7 @@ static void SDL_LogOutputFunction( void * userdata, int category, SDL_LogPriorit
yes:^() {
LOGGER_MESSAGE("delete account [YES]");

[[iOSApplication sharedInstance] removeSessionData];
[iOSApplication.sharedInstance removeSessionData];

ACCOUNT_SERVICE()
->deleteCurrentAccount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ - (instancetype _Nullable) initWithAdUnitIdentifier:(NSString * _Nonnull) adUnit
adView.frame = rect;
adView.backgroundColor = UIColor.clearColor;

UIViewController * rootViewController = [iOSDetail getRootViewController];
[rootViewController.view addSubview:adView];
UIViewController * viewController = [iOSDetail getRootViewController];
[viewController.view addSubview:adView];
adView.hidden = YES;

self.m_adView = adView;
Expand Down
4 changes: 1 addition & 3 deletions src/Plugins/AppleFacebookPlugin/AppleFacebookInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include "Kernel/VectorConstString.h"
#include "Kernel/Params.h"

#include "Config/Lambda.h"

namespace Mengine
{
//////////////////////////////////////////////////////////////////////////
Expand All @@ -24,7 +22,7 @@ namespace Mengine
virtual void onFacebookShareCancel() = 0;
virtual void onFacebookShareError( int32_t _code, const Char * _errorMessage ) = 0;

virtual void onFacebookProfilePictureLinkGetSuccess( const Char * _userId, bool _success, const Char * _pictureURL ) = 0;
virtual void onFacebookProfilePictureLinkGetSuccess( const Char * _userId, const Char * _pictureURL ) = 0;
virtual void onFacebookProfilePictureLinkGetError( int32_t _code, const Char * _errorMessage ) = 0;
};
//////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 2 additions & 1 deletion src/Plugins/AppleFacebookPlugin/AppleFacebookPlugin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
#include "Kernel/OptionHelper.h"
#include "Kernel/FactorableUnique.h"
#include "Kernel/NotificationHelper.h"
#include "Kernel/PluginHelper.h"

//////////////////////////////////////////////////////////////////////////
SERVICE_EXTERN( AppleFacebookService );
//////////////////////////////////////////////////////////////////////////
PLUGIN_FACTORY( AppleFacebook, Mengine::AppleFacebookPlugin )
PLUGIN_FACTORY( AppleFacebook, Mengine::AppleFacebookPlugin );
//////////////////////////////////////////////////////////////////////////
namespace Mengine
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ void onFacebookShareError( int32_t _code, const Char * _errorMessage ) override
this->call_cbs( "onAppleFacebookShareError", _code, _errorMessage );
}

void onFacebookProfilePictureLinkGetSuccess( const Char * _userId, bool _success, const Char * _pictureURL ) override
void onFacebookProfilePictureLinkGetSuccess( const Char * _userId, const Char * _pictureURL ) override
{
this->call_cbs( "onAppleFacebookProfilePictureLinkGetSuccess", _userId, _success, _pictureURL );
this->call_cbs( "onAppleFacebookProfilePictureLinkGetSuccess", _userId, _pictureURL );
}

void onFacebookProfilePictureLinkGetError( int32_t _code, const Char * _errorMessage ) override
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/AppleFacebookPlugin/AppleFacebookService.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ namespace Mengine

protected:
AppleFacebookProviderInterfacePtr m_provider;

FBSDKLoginManager * m_loginManager;

AppleFacebookShareDelegate * m_shareDelegate;
};
}
45 changes: 24 additions & 21 deletions src/Plugins/AppleFacebookPlugin/AppleFacebookService.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "AppleFacebookService.h"

#import "Environment/Apple/AppleErrorHelper.h"
#import "Environment/Apple/AppleDetail.h"
#import "Environment/iOS/iOSApplication.h"
#import "Environment/iOS/iOSDetail.h"
Expand Down Expand Up @@ -29,7 +28,7 @@
bool AppleFacebookService::_initializeService()
{
m_loginManager = [[FBSDKLoginManager alloc] init];
m_shareDelegate = [[AppleFacebookShareDelegate alloc]initWithService: this];
m_shareDelegate = [[AppleFacebookShareDelegate alloc] initWithService: this];

return true;
}
Expand All @@ -54,29 +53,29 @@
//////////////////////////////////////////////////////////////////////////
bool AppleFacebookService::login( const VectorConstString & _permissions )
{
UIViewController * rootViewController = Helper::iOSGetRootViewController();
UIViewController * viewController = [iOSDetail getRootViewController];

NSArray<NSString *> * permissions_ns = Helper::AppleGetNSArrayFromVectorConstString( _permissions );
NSArray<NSString *> * permissions_ns = [AppleDetail getNSArrayFromVectorConstString:_permissions];

NSString * sessionId = [iOSApplication.sharedInstance getSessionId];

FBSDKLoginConfiguration * configuration = [[FBSDKLoginConfiguration alloc] initWithPermissions:permissions_ns
tracking:FBSDKLoginTrackingLimited
nonce:sessionId];

[m_loginManager logInFromViewController:rootViewController configuration:configuration completion:^(FBSDKLoginManagerLoginResult * _Nullable result, NSError * _Nullable error) {
[m_loginManager logInFromViewController:viewController configuration:configuration completion:^(FBSDKLoginManagerLoginResult * _Nullable result, NSError * _Nullable error) {
AppleFacebookProviderInterfacePtr copy_provider = m_provider;

if( error != nullptr )
{
LOGGER_ERROR( "login error: '%s'"
, Helper::AppleGetMessageFromNSError(error).c_str()
, [[AppleDetail getMessageFromNSError:error] UTF8String]
);

if( copy_provider != nullptr )
{
Helper::dispatchMainThreadEvent( [copy_provider, error]() {
copy_provider->onFacebookError( -2, [NSString stringWithFormat:@"%@", error].UTF8String);
copy_provider->onFacebookError( -2, [[AppleDetail getMessageFromNSError:error] UTF8String]);
});
}

Expand All @@ -89,7 +88,7 @@

if( copy_provider != nullptr )
{
Helper::dispatchMainThreadEvent( [copy_provider, error]() {
Helper::dispatchMainThreadEvent( [copy_provider]() {
copy_provider->onFacebookLoginCancel();
});
}
Expand All @@ -111,7 +110,7 @@
NSString * userID = profile.userID;
const Char * userID_str = [userID UTF8String];

params.emplace( STRINGIZE_STRING_LOCAL("profile.userID"), userID_str );
params.emplace( STRINGIZE_STRING_LOCAL("profile.userID"), ParamString(userID_str) );

if( profile.imageURL != nil )
{
Expand All @@ -121,7 +120,7 @@
{
const Char * imageURL_str = [imageURL.absoluteString UTF8String];

params.emplace( STRINGIZE_STRING_LOCAL("profile.imageURL"), imageURL_str );
params.emplace( STRINGIZE_STRING_LOCAL("profile.imageURL"), ParamString(imageURL_str) );
}
}
}
Expand All @@ -133,7 +132,7 @@
NSString * authenticationTokenString = authenticationToken.tokenString;
const Char * authenticationTokenString_str = [authenticationTokenString UTF8String];

params.emplace( STRINGIZE_STRING_LOCAL("authentication.token"), authenticationTokenString_str );
params.emplace( STRINGIZE_STRING_LOCAL("authentication.token"), ParamString(authenticationTokenString_str) );
}

copy_provider->onFacebookLoginSuccess( params );
Expand Down Expand Up @@ -175,7 +174,7 @@

const Char * token_str = authenticationToken.tokenString.UTF8String;

MENGINE_STRNCPY( _token, token_str, _capacity );
StdString::strncpy( _token, token_str, _capacity );

return true;
}
Expand All @@ -193,7 +192,7 @@

const Char * userId_str = userId.UTF8String;

MENGINE_STRNCPY( _userId, userId_str, _capacity );
StdString::strncpy( _userId, userId_str, _capacity );

return true;
}
Expand Down Expand Up @@ -239,9 +238,11 @@
FBSDKShareLinkContent* content = [FBSDKShareLinkContent alloc];
content.contentURL = [NSURL URLWithString:strlink];

UIViewController * rootViewController = Helper::iOSGetRootViewController();
UIViewController * viewController = [iOSDetail getRootViewController];

FBSDKShareDialog * dialog = [FBSDKShareDialog dialogWithViewController:rootViewController withContent:content delegate:m_shareDelegate];
FBSDKShareDialog * dialog = [FBSDKShareDialog dialogWithViewController:viewController
withContent:content
delegate:m_shareDelegate];

[dialog show];
});
Expand Down Expand Up @@ -304,9 +305,11 @@
content.contentURL = [NSURL URLWithString:strlink];
content.media = @[sharePhoto];

UIViewController * rootViewController = Helper::iOSGetRootViewController();
UIViewController * viewController = [iOSDetail getRootViewController];

FBSDKShareDialog * const dialog = [FBSDKShareDialog dialogWithViewController:rootViewController withContent:content delegate:m_shareDelegate];
FBSDKShareDialog * const dialog = [FBSDKShareDialog dialogWithViewController:viewController
withContent:content
delegate:m_shareDelegate];

[dialog show];
});
Expand Down Expand Up @@ -338,7 +341,7 @@
}
}

copy_provider->onFacebookProfilePictureLinkGetSuccess( userID_str, true, imageURL_str );
copy_provider->onFacebookProfilePictureLinkGetSuccess( userID_str, imageURL_str );
});
}

Expand All @@ -349,14 +352,14 @@
if( _error != nil )
{
LOGGER_ERROR( "get picture error: %s"
, Helper::AppleGetMessageFromNSError(_error).c_str()
, [[AppleDetail getMessageFromNSError:_error] UTF8String]
);

if( copy_provider != nullptr )
{
Helper::dispatchMainThreadEvent( [copy_provider, _error]() {
NSInteger error_code = _error.code;
const Char * error_message = _error.localizedDescription.UTF8String;
const Char * error_message = [_error.description UTF8String];

copy_provider->onFacebookProfilePictureLinkGetError( (int32_t)error_code, error_message );
});
Expand Down Expand Up @@ -415,7 +418,7 @@
NSString * imageURL = _profile.imageURL.absoluteURL.absoluteString;
const Char * imageURL_str = imageURL.UTF8String;

copy_provider->onFacebookProfilePictureLinkGetSuccess( userID_str, true, imageURL_str );
copy_provider->onFacebookProfilePictureLinkGetSuccess( userID_str, imageURL_str );
});
}
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ - (void) sharer:(id <FBSDKSharing> _Nonnull) sharer didFailWithError:(NSError *

Mengine::Helper::dispatchMainThreadEvent([copy_provider, error](){
NSInteger code = error.code;
const char * message = error.localizedDescription.UTF8String;
const char * message = [error.description UTF8String];

copy_provider->onFacebookShareError( (int32_t)code, message );
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
void AppleFirebaseCrashlyticsService::recordError( NSError * _error )
{
LOGGER_MESSAGE( "record error: %s"
, [AppleDetail getMessageFromNSError:_error].c_str()
, [[AppleDetail getMessageFromNSError:_error] UTF8String]
);

[[FIRCrashlytics crashlytics] recordError:_error];
Expand Down
10 changes: 5 additions & 5 deletions src/Plugins/AppleGameCenterPlugin/AppleGameCenterService.mm
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
m_achievementsComplete.clear();

LOGGER_ERROR( "login error: '%s'"
, [AppleDetail getMessageFromNSError:_error].c_str()
, [[AppleDetail getMessageFromNSError:_error] UTF8String]
);

if( copy_provider != nullptr )
Expand Down Expand Up @@ -106,7 +106,7 @@
m_achievementsSynchronization = false;

LOGGER_ERROR("load completed achievements error: '%s'"
, [AppleDetail getMessageFromNSError:_error].c_str()
, [[AppleDetail getMessageFromNSError:_error] UTF8String]
);

if( provider != nullptr )
Expand Down Expand Up @@ -175,7 +175,7 @@
LOGGER_ERROR( "response achievement '%s' [%lf] error: %s"
, copy_achievementName.c_str()
, _percentComplete
, [AppleDetail getMessageFromNSError:_error].c_str()
, [[AppleDetail getMessageFromNSError:_error] UTF8String]
);

Mengine::Helper::dispatchMainThreadEvent([copy_response]() {
Expand Down Expand Up @@ -231,7 +231,7 @@
if( _error != nil )
{
LOGGER_ERROR( "reset achievemnts error: '%s'"
, [AppleDetail getMessageFromNSError:_error].c_str()
, [[AppleDetail getMessageFromNSError:_error] UTF8String]
);

return;
Expand Down Expand Up @@ -268,7 +268,7 @@
LOGGER_ERROR( "response score '%s' [%lld] error: %s"
, copy_key.c_str()
, _score
, [AppleDetail getMessageFromNSError:_error].c_str()
, [[AppleDetail getMessageFromNSError:_error] UTF8String]
);

Mengine::Helper::dispatchMainThreadEvent([copy_response]() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ - (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedW
}

LOGGER_MESSAGE( "SKPaymentTransactionObserver paymentQueue restoreCompletedTransactionsFailedWithError: %s"
, [AppleDetail getMessageFromNSError:error].c_str()
, [[AppleDetail getMessageFromNSError:error] UTF8String]
);

//ToDo
Expand Down Expand Up @@ -195,7 +195,7 @@ - (void)paymentQueue:(SKPaymentQueue *)queue didRevokeEntitlementsForProductIden
}

LOGGER_MESSAGE( "SKPaymentTransactionObserver didRevokeEntitlementsForProductIdentifiers: %s"
, [AppleDetail NSIdToString:productIdentifiers].c_str()
, [[AppleDetail NSIdToString:productIdentifiers] UTF8String]
);

//ToDo
Expand Down
Loading

0 comments on commit 434d03a

Please sign in to comment.