Skip to content

Commit

Permalink
Merge pull request #23 from Web3Auth/fix_ios
Browse files Browse the repository at this point in the history
fix: ios packaging
  • Loading branch information
grvgoel81 authored Dec 5, 2023
2 parents 7daa0e0 + fdd6d15 commit e005a34
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Binary file modified Content/Example.umap
Binary file not shown.
25 changes: 17 additions & 8 deletions Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,30 @@
#include "IOS/ObjC/WebAuthenticate.h"
#endif

#if PLATFORM_ANDROID

#if PLATFORM_ANDROID || PLATFORM_IOS
// Need to keep a pointer to self later.
// How this works is:
// Android:
// 1) Just before opening BrowserView, assign thiz to the current instance. Code then moves from C++ to Java.
// 2) When returning from BrowserView, onDeepLink is called. Code returns to C++ from Java
// 3) In the implementation of onDeepLink, thiz is used to call the c++ method (setResultUrl) on this instance.
UWeb3Auth* thiz = nullptr;
// IOS:
// 1) Just before opening WebAuthenticate, assign thiz to the current instance. Code then moves from C++ to ObjC.
// 2) When returning from WebAuthenticate, callBackFromWebAuthenticateIOS is called. Code returns to C++ from ObjC.
// 3) In the implementation of callBackFromWebAuthenticateIOS, thiz is used to call the c++ method (setResultUrl) on this instance.

UWeb3Auth* thiz_instance = nullptr;

#endif

#if PLATFORM_ANDROID
JNI_METHOD void Java_com_epicgames_unreal_GameActivity_onDeepLink(JNIEnv* env, jclass clazz, jstring uri) {
if (JNIEnv* Env = FAndroidApplication::GetJavaEnv(true)) {
const char* UTFString = Env->GetStringUTFChars(uri, 0);

FString result = FString(UTF8_TO_TCHAR(UTFString));
UE_LOG(LogTemp, Warning, TEXT("redirect %s"), *result);
thiz->setResultUrl(result);
thiz_instance->setResultUrl(result);

Env->ReleaseStringUTFChars(uri, UTFString);
Env->DeleteLocalRef(uri);
Expand Down Expand Up @@ -136,7 +144,7 @@ void UWeb3Auth::request(FString path, FLoginParams* loginParams = NULL, TShared
FString url = web3AuthOptions.sdkUrl + "/" + path + "#" + base64;

#if PLATFORM_ANDROID
thiz = this;
thiz_instance = this;

if (JNIEnv* Env = FAndroidApplication::GetJavaEnv(true)) {
jstring jurl = Env->NewStringUTF(TCHAR_TO_UTF8(*url));
Expand All @@ -147,6 +155,8 @@ void UWeb3Auth::request(FString path, FLoginParams* loginParams = NULL, TShared
CallJniVoidMethod(Env, jbrowserViewClass, jlaunchUrl, FJavaWrapper::GameActivityThis, jurl);
}
#elif PLATFORM_IOS
thiz_instance = this;

[[WebAuthenticate Singleton] launchUrl:TCHAR_TO_ANSI(*url)];
#else
FPlatformProcess::LaunchURL(*url, NULL, NULL);
Expand Down Expand Up @@ -246,7 +256,7 @@ bool UWeb3Auth::requestAuthCallback(const FHttpServerRequest& Request, const FHt
FString code = Request.QueryParams["code"];

if (!code.IsEmpty()) {
UWeb3Auth::setResultUrl(code);
setResultUrl(code);
}

TUniquePtr<FHttpServerResponse> response = FHttpServerResponse::Create(TEXT("OK"), TEXT("text/html"));
Expand Down Expand Up @@ -319,8 +329,7 @@ void UWeb3Auth::setLogoutEvent(FOnLogout _event) {
#if PLATFORM_IOS
void UWeb3Auth::callBackFromWebAuthenticateIOS(NSString* sResult) {
FString result = FString(sResult);
//TODO: Fix this
//UWeb3Auth::setResultUrl(result);
thiz_instance->setResultUrl(result);
}
#endif

Expand Down

0 comments on commit e005a34

Please sign in to comment.