Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge mrexodia/uri-handlers #17

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cmake/templates/IOSInfo.plist.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
<key>UILaunchStoryboardName</key>
<string>${MACOSX_BUNDLE_LAUNCH_STORYBOARD}</string>
${MACOSX_NSAPP_TRANSPORT_SECURITY}
${IOS_SUPPORTED_INTERFACE_ORIENTATIONS}
${MACOSX_NSAPP_TRANSPORT_SECURITY}
${IOS_SUPPORTED_INTERFACE_ORIENTATIONS}
${IOS_URI_HANDLERS}
${IOS_ADDITIONAL_PLIST_PROPERTIES}
</dict>
</plist>

3 changes: 2 additions & 1 deletion cmake/templates/OSXInfo.plist.in
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<true/>
<key>NSHumanReadableCopyright</key>
<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
${MACOSX_NSAPP_TRANSPORT_SECURITY}
${MACOSX_NSAPP_TRANSPORT_SECURITY}
${MACOSX_ADDITIONAL_PLIST_PROPERTIES}
</dict>
</plist>
57 changes: 47 additions & 10 deletions cmake/utilities/ios.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ macro(ios_build_orientation_entries OUT )
set(multiValueArgs )
cmake_parse_arguments(_ARGUMENTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

set(${OUT} "<array>\n")
set(${OUT} " <array>\n")

if(_ARGUMENTS_ALL OR _ARGUMENTS_PORTRAIT)
set(${OUT} "${${OUT}}<string>UIInterfaceOrientationPortrait</string>\n")
set(${OUT} "${${OUT}} <string>UIInterfaceOrientationPortrait</string>\n")
endif()
if(_ARGUMENTS_ALL OR _ARGUMENTS_LANDSCAPE_LEFT)
set(${OUT} "${${OUT}}<string>UIInterfaceOrientationLandscapeLeft</string>\n")
set(${OUT} "${${OUT}} <string>UIInterfaceOrientationLandscapeLeft</string>\n")
endif()
if(_ARGUMENTS_ALL OR _ARGUMENTS_LANDSCAPE_RIGHT)
set(${OUT} "${${OUT}}<string>UIInterfaceOrientationLandscapeRight</string>\n")
set(${OUT} "${${OUT}} <string>UIInterfaceOrientationLandscapeRight</string>\n")
endif()
if(_ARGUMENTS_ALL OR _ARGUMENTS_UPSIDEDOWN)
set(${OUT} "${${OUT}}<string>UIInterfaceOrientationPortraitUpsideDown</string>\n")
set(${OUT} "${${OUT}} <string>UIInterfaceOrientationPortraitUpsideDown</string>\n")
endif()

set(${OUT} "${${OUT}}</array>\n")
set(${OUT} "${${OUT}} </array>\n")
endmacro()

macro(ios_supported_orientations)
Expand All @@ -71,17 +71,46 @@ macro(ios_supported_orientations)
set(result "")
if(_TARGET_IPHONE)
ios_build_orientation_entries(_iphone_entries ${_TARGET_IPHONE})
set(result "${result}<key>UISupportedInterfaceOrientations</key>\n${_iphone_entries}")
set(result "${result} <key>UISupportedInterfaceOrientations</key>\n${_iphone_entries}")
endif()
if(_TARGET_IPAD)
ios_build_orientation_entries(_ipad_entries ${_TARGET_IPAD})
set(result "${result}<key>UISupportedInterfaceOrientations~ipad</key>\n${_ipad_entries}")
set(result "${result} <key>UISupportedInterfaceOrientations~ipad</key>\n${_ipad_entries}")
endif()

set(IOS_SUPPORTED_INTERFACE_ORIENTATIONS ${result})
endif()
endmacro()

macro(ios_uri_handlers)
if(BDN_PLATFORM_IOS)
set(options)
set(oneValueArgs ROLE)
set(multiValueArgs HANDLERS)
cmake_parse_arguments(_ARGUMENTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

set(result "")
if(_ARGUMENTS_HANDLERS)
set(result "${result} <key>CFBundleURLTypes</key>\n")
set(result "${result} <array>\n")
set(result "${result} <dict>\n")
set(result "${result} <key>CFBundleTypeRole</key>\n")
set(result "${result} <string>${_ARGUMENTS_ROLE}</string>\n")
set(result "${result} <key>CFBundleURLName</key>\n")
set(result "${result} <string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>\n")
set(result "${result} <key>CFBundleURLSchemes</key>\n")
set(result "${result} <array>\n")
string(REPLACE ";" "</string>\n <string>" _ARGUMENTS_HANDLERS "${_ARGUMENTS_HANDLERS}")
set(result "${result} <string>${_ARGUMENTS_HANDLERS}</string>\n")
set(result "${result} </array>\n")
set(result "${result} </dict>\n")
set(result "${result} </array>\n")
endif()

set(IOS_URI_HANDLERS ${result})
endif()
endmacro()

macro(ios_set_launchboard_file LAUNCHBOARD_NAME)
SET(MACOSX_BUNDLE_LAUNCH_STORYBOARD ${LAUNCHBOARD_NAME})
endmacro()
Expand All @@ -96,8 +125,8 @@ endmacro()
macro(ios_configure_app_info)
if(BDN_PLATFORM_IOS)
set(options )
set(oneValueArgs TARGET LAUNCHSCREEN)
set(multiValueArgs TARGETED_DEVICES IPHONE_ORIENTATIONS IPAD_ORIENTATIONS)
set(oneValueArgs TARGET LAUNCHSCREEN URI_ROLE)
set(multiValueArgs TARGETED_DEVICES IPHONE_ORIENTATIONS IPAD_ORIENTATIONS URI_HANDLERS)
cmake_parse_arguments(_ARGUMENTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

set_xcode_property(${_ARGUMENTS_TARGET} INSTALL_PATH "$(LOCAL_APPS_DIR)")
Expand All @@ -110,6 +139,14 @@ macro(ios_configure_app_info)
endif()

ios_supported_orientations(IPHONE ${_ARGUMENTS_IPHONE_ORIENTATIONS} IPAD ${_ARGUMENTS_IPAD_ORIENTATIONS})

if(_ARGUMENTS_URI_HANDLERS)
if(NOT _ARGUMENTS_URI_ROLE)
# Options: Editor / Viewer / None
set(_ARGUMENTS_URI_ROLE None)
endif()
ios_uri_handlers(HANDLERS ${_ARGUMENTS_URI_HANDLERS} ROLE ${_ARGUMENTS_URI_ROLE})
endif()
endif()
endmacro()

Expand Down
10 changes: 5 additions & 5 deletions cmake/utilities/permissions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ macro(configure_app_permissions)
cmake_parse_arguments(_permissions "${options}" "" "" ${ARGN} )

if(BDN_PLATFORM_IOS OR BDN_PLATFORM_OSX)
set(_transport_security "<key>NSAppTransportSecurity</key><dict>")
set(_transport_security " <key>NSAppTransportSecurity</key>\n <dict>")

# Allow HTTP
string(APPEND _transport_security "<key>NSAllowsArbitraryLoadsInWebContent</key>")
string(APPEND _transport_security " <key>NSAllowsArbitraryLoadsInWebContent</key>")

if(_permissions_ALLOW_HTTP)
string(APPEND _transport_security "<true/>")
string(APPEND _transport_security " <true/>")
else()
string(APPEND _transport_security "<false/>")
string(APPEND _transport_security " <false/>")
endif()

string(APPEND _transport_security "</dict>")
string(APPEND _transport_security " </dict>\n")
set(MACOSX_NSAPP_TRANSPORT_SECURITY ${_transport_security})
elseif(BDN_PLATFORM_ANDROID)
set(ANDROID_PERMISSIONS "")
Expand Down
2 changes: 2 additions & 0 deletions framework/foundation/include/bdn/ApplicationController.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <bdn/String.h>
#include <memory>

namespace bdn
Expand All @@ -17,5 +18,6 @@ namespace bdn
virtual void onSuspend() {}
virtual void onResume() {}
virtual void onTerminate() {}
virtual void onOpenURL(const String &url) {}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace bdn::ui::ios
void _applicationDidEnterBackground();
void _applicationWillEnterForeground();
void _applicationWillTerminate();
bool _applicationOpenURL(NSURL *url);

private:
void buildCommandlineArguments(int argCount, char *args[]);
Expand Down
20 changes: 20 additions & 0 deletions framework/ui/platforms/ios/src/UIApplication.mm
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ - (void)applicationWillTerminate:(UIApplication *)application
}
}

- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
{
if (auto app = self.bdnApplication.lock()) {
return app->_applicationOpenURL(url) ? YES : NO;
}
return NO;
}

@end

namespace bdn::ui::ios
Expand Down Expand Up @@ -188,6 +198,16 @@ - (void)applicationWillTerminate:(UIApplication *)application
bdn::platformEntryWrapper([&]() { applicationController()->onTerminate(); }, false);
}

bool UIApplication::_applicationOpenURL(NSURL *url)
{
if (!url) {
return false;
}
bdn::String bdnUrl = [url absoluteString].UTF8String;
bdn::platformEntryWrapper([&]() { applicationController()->onOpenURL(bdnUrl); }, false);
return true;
}

void UIApplication::initiateExitIfPossible(int exitCode) {}

void UIApplication::disposeMainDispatcher()
Expand Down