diff --git a/Content/Example.umap b/Content/Example.umap index 0fd5ce4..5dc9570 100644 Binary files a/Content/Example.umap and b/Content/Example.umap differ diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp index 979f5f4..40a0041 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp @@ -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); @@ -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)); @@ -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); @@ -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 response = FHttpServerResponse::Create(TEXT("OK"), TEXT("text/html")); @@ -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