From 0c97694b79ca6f6fb0e19705b522f9adb1a75a66 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Tue, 23 Jul 2019 16:11:42 +0200 Subject: [PATCH 1/4] Improve whitespace situation in Info.plist generation --- cmake/templates/IOSInfo.plist.in | 5 ++--- cmake/templates/OSXInfo.plist.in | 2 +- cmake/utilities/ios.cmake | 16 ++++++++-------- cmake/utilities/permissions.cmake | 10 +++++----- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/cmake/templates/IOSInfo.plist.in b/cmake/templates/IOSInfo.plist.in index f14de6e4..16c291a2 100644 --- a/cmake/templates/IOSInfo.plist.in +++ b/cmake/templates/IOSInfo.plist.in @@ -32,8 +32,7 @@ ${MACOSX_BUNDLE_COPYRIGHT} UILaunchStoryboardName ${MACOSX_BUNDLE_LAUNCH_STORYBOARD} - ${MACOSX_NSAPP_TRANSPORT_SECURITY} - ${IOS_SUPPORTED_INTERFACE_ORIENTATIONS} +${MACOSX_NSAPP_TRANSPORT_SECURITY} +${IOS_SUPPORTED_INTERFACE_ORIENTATIONS} - diff --git a/cmake/templates/OSXInfo.plist.in b/cmake/templates/OSXInfo.plist.in index cfd75570..e18e888e 100644 --- a/cmake/templates/OSXInfo.plist.in +++ b/cmake/templates/OSXInfo.plist.in @@ -36,6 +36,6 @@ NSHumanReadableCopyright ${MACOSX_BUNDLE_COPYRIGHT} - ${MACOSX_NSAPP_TRANSPORT_SECURITY} +${MACOSX_NSAPP_TRANSPORT_SECURITY} diff --git a/cmake/utilities/ios.cmake b/cmake/utilities/ios.cmake index b6d7db22..61788fe7 100644 --- a/cmake/utilities/ios.cmake +++ b/cmake/utilities/ios.cmake @@ -43,22 +43,22 @@ macro(ios_build_orientation_entries OUT ) set(multiValueArgs ) cmake_parse_arguments(_ARGUMENTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) - set(${OUT} "\n") + set(${OUT} " \n") if(_ARGUMENTS_ALL OR _ARGUMENTS_PORTRAIT) - set(${OUT} "${${OUT}}UIInterfaceOrientationPortrait\n") + set(${OUT} "${${OUT}} UIInterfaceOrientationPortrait\n") endif() if(_ARGUMENTS_ALL OR _ARGUMENTS_LANDSCAPE_LEFT) - set(${OUT} "${${OUT}}UIInterfaceOrientationLandscapeLeft\n") + set(${OUT} "${${OUT}} UIInterfaceOrientationLandscapeLeft\n") endif() if(_ARGUMENTS_ALL OR _ARGUMENTS_LANDSCAPE_RIGHT) - set(${OUT} "${${OUT}}UIInterfaceOrientationLandscapeRight\n") + set(${OUT} "${${OUT}} UIInterfaceOrientationLandscapeRight\n") endif() if(_ARGUMENTS_ALL OR _ARGUMENTS_UPSIDEDOWN) - set(${OUT} "${${OUT}}UIInterfaceOrientationPortraitUpsideDown\n") + set(${OUT} "${${OUT}} UIInterfaceOrientationPortraitUpsideDown\n") endif() - set(${OUT} "${${OUT}}\n") + set(${OUT} "${${OUT}} \n") endmacro() macro(ios_supported_orientations) @@ -71,11 +71,11 @@ macro(ios_supported_orientations) set(result "") if(_TARGET_IPHONE) ios_build_orientation_entries(_iphone_entries ${_TARGET_IPHONE}) - set(result "${result}UISupportedInterfaceOrientations\n${_iphone_entries}") + set(result "${result} UISupportedInterfaceOrientations\n${_iphone_entries}") endif() if(_TARGET_IPAD) ios_build_orientation_entries(_ipad_entries ${_TARGET_IPAD}) - set(result "${result}UISupportedInterfaceOrientations~ipad\n${_ipad_entries}") + set(result "${result} UISupportedInterfaceOrientations~ipad\n${_ipad_entries}") endif() set(IOS_SUPPORTED_INTERFACE_ORIENTATIONS ${result}) diff --git a/cmake/utilities/permissions.cmake b/cmake/utilities/permissions.cmake index de7a7050..89b52f61 100644 --- a/cmake/utilities/permissions.cmake +++ b/cmake/utilities/permissions.cmake @@ -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 "NSAppTransportSecurity") + set(_transport_security " NSAppTransportSecurity\n ") # Allow HTTP - string(APPEND _transport_security "NSAllowsArbitraryLoadsInWebContent") + string(APPEND _transport_security " NSAllowsArbitraryLoadsInWebContent") if(_permissions_ALLOW_HTTP) - string(APPEND _transport_security "") + string(APPEND _transport_security " ") else() - string(APPEND _transport_security "") + string(APPEND _transport_security " ") endif() - string(APPEND _transport_security "") + string(APPEND _transport_security " \n") set(MACOSX_NSAPP_TRANSPORT_SECURITY ${_transport_security}) elseif(BDN_PLATFORM_ANDROID) set(ANDROID_PERMISSIONS "") From 8ba3ba239c2f6e0ff4ead2919f4717654034ee91 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Tue, 23 Jul 2019 16:12:49 +0200 Subject: [PATCH 2/4] Add MACOSX/IOS_ADDITIONAL_PLIST_PROPERTIES variable to Info.plist template --- cmake/templates/IOSInfo.plist.in | 1 + cmake/templates/OSXInfo.plist.in | 1 + 2 files changed, 2 insertions(+) diff --git a/cmake/templates/IOSInfo.plist.in b/cmake/templates/IOSInfo.plist.in index 16c291a2..242c690f 100644 --- a/cmake/templates/IOSInfo.plist.in +++ b/cmake/templates/IOSInfo.plist.in @@ -34,5 +34,6 @@ ${MACOSX_BUNDLE_LAUNCH_STORYBOARD} ${MACOSX_NSAPP_TRANSPORT_SECURITY} ${IOS_SUPPORTED_INTERFACE_ORIENTATIONS} +${IOS_ADDITIONAL_PLIST_PROPERTIES} diff --git a/cmake/templates/OSXInfo.plist.in b/cmake/templates/OSXInfo.plist.in index e18e888e..b1075386 100644 --- a/cmake/templates/OSXInfo.plist.in +++ b/cmake/templates/OSXInfo.plist.in @@ -37,5 +37,6 @@ NSHumanReadableCopyright ${MACOSX_BUNDLE_COPYRIGHT} ${MACOSX_NSAPP_TRANSPORT_SECURITY} +${MACOSX_ADDITIONAL_PLIST_PROPERTIES} From 7175d1a33e1c958794f2d06d17bc0437c868325c Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Tue, 23 Jul 2019 16:14:21 +0200 Subject: [PATCH 3/4] Add Uri handler support for iOS Info.plist --- cmake/templates/IOSInfo.plist.in | 1 + cmake/utilities/ios.cmake | 41 ++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/cmake/templates/IOSInfo.plist.in b/cmake/templates/IOSInfo.plist.in index 242c690f..8ca2587e 100644 --- a/cmake/templates/IOSInfo.plist.in +++ b/cmake/templates/IOSInfo.plist.in @@ -34,6 +34,7 @@ ${MACOSX_BUNDLE_LAUNCH_STORYBOARD} ${MACOSX_NSAPP_TRANSPORT_SECURITY} ${IOS_SUPPORTED_INTERFACE_ORIENTATIONS} +${IOS_URI_HANDLERS} ${IOS_ADDITIONAL_PLIST_PROPERTIES} diff --git a/cmake/utilities/ios.cmake b/cmake/utilities/ios.cmake index 61788fe7..d61f1053 100644 --- a/cmake/utilities/ios.cmake +++ b/cmake/utilities/ios.cmake @@ -82,6 +82,35 @@ macro(ios_supported_orientations) 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} CFBundleURLTypes\n") + set(result "${result} \n") + set(result "${result} \n") + set(result "${result} CFBundleTypeRole\n") + set(result "${result} ${_ARGUMENTS_ROLE}\n") + set(result "${result} CFBundleURLName\n") + set(result "${result} ${MACOSX_BUNDLE_GUI_IDENTIFIER}\n") + set(result "${result} CFBundleURLSchemes\n") + set(result "${result} \n") + string(REPLACE ";" "\n " _ARGUMENTS_HANDLERS "${_ARGUMENTS_HANDLERS}") + set(result "${result} ${_ARGUMENTS_HANDLERS}\n") + set(result "${result} \n") + set(result "${result} \n") + set(result "${result} \n") + endif() + + set(IOS_URI_HANDLERS ${result}) + endif() +endmacro() + macro(ios_set_launchboard_file LAUNCHBOARD_NAME) SET(MACOSX_BUNDLE_LAUNCH_STORYBOARD ${LAUNCHBOARD_NAME}) endmacro() @@ -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)") @@ -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() From 4a30633359598c7eb691b60529a36d5e05b4e311 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Tue, 23 Jul 2019 17:18:03 +0200 Subject: [PATCH 4/4] Add ApplicationController::onOpenURL --- .../include/bdn/ApplicationController.h | 2 ++ .../ios/include/bdn/ios/UIApplication.hh | 1 + .../ui/platforms/ios/src/UIApplication.mm | 20 +++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/framework/foundation/include/bdn/ApplicationController.h b/framework/foundation/include/bdn/ApplicationController.h index ba024e64..f3c8b7cf 100644 --- a/framework/foundation/include/bdn/ApplicationController.h +++ b/framework/foundation/include/bdn/ApplicationController.h @@ -1,5 +1,6 @@ #pragma once +#include #include namespace bdn @@ -17,5 +18,6 @@ namespace bdn virtual void onSuspend() {} virtual void onResume() {} virtual void onTerminate() {} + virtual void onOpenURL(const String &url) {} }; } diff --git a/framework/ui/platforms/ios/include/bdn/ios/UIApplication.hh b/framework/ui/platforms/ios/include/bdn/ios/UIApplication.hh index 6d8e4fa2..18948ee8 100644 --- a/framework/ui/platforms/ios/include/bdn/ios/UIApplication.hh +++ b/framework/ui/platforms/ios/include/bdn/ios/UIApplication.hh @@ -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[]); diff --git a/framework/ui/platforms/ios/src/UIApplication.mm b/framework/ui/platforms/ios/src/UIApplication.mm index dd9b7411..fc928990 100644 --- a/framework/ui/platforms/ios/src/UIApplication.mm +++ b/framework/ui/platforms/ios/src/UIApplication.mm @@ -78,6 +78,16 @@ - (void)applicationWillTerminate:(UIApplication *)application } } +- (BOOL)application:(UIApplication *)app + openURL:(NSURL *)url + options:(NSDictionary *)options +{ + if (auto app = self.bdnApplication.lock()) { + return app->_applicationOpenURL(url) ? YES : NO; + } + return NO; +} + @end namespace bdn::ui::ios @@ -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()