Skip to content

Commit

Permalink
[Cloud]iOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
OFFTKP committed Dec 17, 2023
1 parent 14af909 commit dcaad11
Show file tree
Hide file tree
Showing 5 changed files with 3,562 additions and 7 deletions.
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ set(SOKOL_HEADERS
if(ANDROID)
add_definitions(-DSE_PLATFORM_ANDROID)
set(LINK_LIBS ${LINK_LIBS} GLESv3 EGL OpenSLES log android)
# link_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/curl-mobile/android/${ANDROID_ABI})
# include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/curl-mobile/android/include)
message("Android Build!")
endif()
if(MACOS OR IOS)
Expand Down Expand Up @@ -299,9 +297,6 @@ endif()
if(IOS)
set(SKYEMU_SRC ${SKYEMU_SRC} src/ios_support.m)
add_definitions(-DSE_PLATFORM_IOS)
# set(LINK_LIBS ${LINK_LIBS} curl z)
# link_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/curl-mobile/iOS)
# include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/curl-mobile/iOS/include)
endif()

if(WIN32)
Expand Down
19 changes: 17 additions & 2 deletions src/cloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const char* se_get_pref_path();
extern "C" const void* sapp_android_get_native_activity();
#endif

#ifdef SE_PLATFORM_IOS
extern "C" {
#include "ios_support.h"
}
#endif

struct file_metadata_t
{
std::string id;
Expand Down Expand Up @@ -254,6 +260,7 @@ enum class http_request_e
const char* get_ca_path()
{
static std::string ca_path;
#ifdef SE_PLATFORM_ANDROID
if (ca_path.empty())
{
ANativeActivity* activity = (ANativeActivity*)sapp_android_get_native_activity();
Expand All @@ -272,6 +279,12 @@ const char* get_ca_path()
pJavaVM->DetachCurrentThread();
}
}
#elif defined(SE_PLATFORM_IOS)
if (ca_path.empty())
{
ca_path = se_ios_get_certificate_path();
}
#endif
return ca_path.c_str();
}
#endif
Expand All @@ -294,7 +307,7 @@ void https_request(http_request_e type, const std::string& url, const std::strin
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&result);
#ifdef SE_PLATFORM_ANDROID
#if defined(SE_PLATFORM_ANDROID) || defined(SE_PLATFORM_IOS)
curl_easy_setopt(curl, CURLOPT_CAINFO, get_ca_path());
#endif

Expand Down Expand Up @@ -650,7 +663,7 @@ void cloud_drive_authenticate(cloud_drive_t* drive)
{
#ifdef EMSCRIPTEN
return em_oath_sign_in(drive, GOOGLE_CLIENT_ID_WEB);
#elif !defined(SE_PLATFORM_IOS)
#else
srand(time(NULL));
const char* charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
std::string code_verifier;
Expand Down Expand Up @@ -691,6 +704,8 @@ void cloud_drive_authenticate(cloud_drive_t* drive)
pJNIEnv->CallVoidMethod(nativeActivity, MethodOpenURL, jstrURL);
pJavaVM->DetachCurrentThread();
}
#elif SE_PLATFORM_IOS
se_ios_open_url(request.c_str());
#else
printf("Navigate to the following URL to authorize the application:\n%s\n", request.c_str());
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/ios_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
void se_ios_open_file_picker( int num_extensions, const char ** extensions);
void se_ios_get_safe_ui_padding(float *top, float* bottom,float* left, float *right);
void se_ios_set_documents_working_directory();
void se_ios_open_url(const char * url);
const char* se_ios_get_certificate_path();
#endif
9 changes: 9 additions & 0 deletions src/ios_support.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,12 @@ void se_ios_get_safe_ui_padding(float *top, float* bottom,float* left, float *ri
if(right)*right = window.safeAreaInsets.right;
}
}
void se_ios_open_url(const char * url){
NSString* urlString = [NSString stringWithUTF8String:url];
NSURL* nsurl = [NSURL URLWithString:urlString];
[[UIApplication sharedApplication] openURL:nsurl options:@{} completionHandler:nil];
}
const char* se_ios_get_certificate_path(){
NSString* path = [[NSBundle mainBundle] pathForResource:@"cacert" ofType:@"pem"];
return [path cStringUsingEncoding:NSUTF8StringEncoding];
}
Loading

0 comments on commit dcaad11

Please sign in to comment.