From de74c60d268f51fa1139f8e46e40710baf029f54 Mon Sep 17 00:00:00 2001 From: Zilin Zhang Date: Mon, 25 Sep 2023 22:10:42 -0700 Subject: [PATCH] Fix Build issue in XCode 14 Summary: Fix backward compatibility for building the URL API for Xcode 14. In OC, we use __IPHONE_OS_VERSION_MAX_ALLOWED to check the iOS 17 SDK. In Swift, we use `#if swift(>=5.9)` to check the iOS 17 SDK (swift compiler is 5.9 in XCode 15) Reviewed By: sway-git, xta0 Differential Revision: D49626160 fbshipit-source-id: c702fb4208634720e78ed549ae6cd647f0f6e464 --- FBSDKCoreKit/FBSDKCoreKit/FBSDKInternalUtility.m | 8 +++++--- FBSDKCoreKit/FBSDKCoreKit/Profile+Loading.swift | 3 +++ .../FBSDKCoreKitTests/AppLinkNavigationTests.swift | 4 ++++ .../BridgeAPI+SessionCompletionHandlerTests.swift | 2 ++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/FBSDKCoreKit/FBSDKCoreKit/FBSDKInternalUtility.m b/FBSDKCoreKit/FBSDKCoreKit/FBSDKInternalUtility.m index e78be08b4..e4696692d 100644 --- a/FBSDKCoreKit/FBSDKCoreKit/FBSDKInternalUtility.m +++ b/FBSDKCoreKit/FBSDKCoreKit/FBSDKInternalUtility.m @@ -327,12 +327,14 @@ - (nullable NSURL *)URLWithScheme:(NSString *)scheme host ?: @"", path ?: @"", queryString ?: @""]; - NSURL *url; + NSURL *url = [NSURL URLWithString:urlString]; + +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000 if (@available(iOS 17.0, *)) { url = [NSURL URLWithString:urlString encodingInvalidCharacters:NO]; - } else { - url = [NSURL URLWithString:urlString]; } +#endif + if (errorRef != NULL) { if (url) { *errorRef = nil; diff --git a/FBSDKCoreKit/FBSDKCoreKit/Profile+Loading.swift b/FBSDKCoreKit/FBSDKCoreKit/Profile+Loading.swift index 0691c1f23..454ef7d2f 100644 --- a/FBSDKCoreKit/FBSDKCoreKit/Profile+Loading.swift +++ b/FBSDKCoreKit/FBSDKCoreKit/Profile+Loading.swift @@ -103,11 +103,14 @@ extension Profile { let rawLinkURL = response[ResponseKey.link.rawValue] as? String var linkURL = (response[ResponseKey.link.rawValue] as? URL) ?? (rawLinkURL.flatMap(URL.init(string:))) + + #if swift(>=5.9) if #available(iOS 17.0, *) { linkURL = (response[ResponseKey.link.rawValue] as? URL) ?? rawLinkURL.flatMap { str in URL(string: str, encodingInvalidCharacters: false) } } + #endif let friendsResponse = response[ResponseKey.friends.rawValue] as? [String: Any] let friends = friendsResponse.flatMap(friendIdentifiers(from:)) diff --git a/FBSDKCoreKit/FBSDKCoreKitTests/AppLinkNavigationTests.swift b/FBSDKCoreKit/FBSDKCoreKitTests/AppLinkNavigationTests.swift index 8898a6225..ec69794e7 100644 --- a/FBSDKCoreKit/FBSDKCoreKitTests/AppLinkNavigationTests.swift +++ b/FBSDKCoreKit/FBSDKCoreKitTests/AppLinkNavigationTests.swift @@ -365,9 +365,11 @@ final class AppLinkNavigationTests: XCTestCase { func testNavigationTypeWithInvalidTargetWithoutWebUrl() { var url = URL(string: "invalid url") + #if swift(>=5.9) if #available(iOS 17.0, *) { url = URL(string: "invalid url", encodingInvalidCharacters: false) } + #endif let target = AppLinkTarget(url: url, appStoreId: nil, appName: name) let appLink = AppLink(sourceURL: nil, targets: [target], webURL: nil) navigation = AppLinkNavigation(appLink: appLink, extras: [:], appLinkData: [:]) @@ -405,9 +407,11 @@ final class AppLinkNavigationTests: XCTestCase { func testNavigationTypeWithInvalidTargetWithWebUrl() { var url = URL(string: "invalid url") + #if swift(>=5.9) if #available(iOS 17.0, *) { url = URL(string: "invalid url", encodingInvalidCharacters: false) } + #endif let target = AppLinkTarget(url: url, appStoreId: nil, appName: name) let appLink = AppLink(sourceURL: nil, targets: [target], webURL: .usingHost1) navigation = AppLinkNavigation(appLink: appLink, extras: [:], appLinkData: [:]) diff --git a/FBSDKCoreKit/FBSDKCoreKitTests/Internal/BridgeAPI/BridgeAPI+SessionCompletionHandlerTests.swift b/FBSDKCoreKit/FBSDKCoreKitTests/Internal/BridgeAPI/BridgeAPI+SessionCompletionHandlerTests.swift index 5056f1e9e..72babed70 100644 --- a/FBSDKCoreKit/FBSDKCoreKitTests/Internal/BridgeAPI/BridgeAPI+SessionCompletionHandlerTests.swift +++ b/FBSDKCoreKit/FBSDKCoreKitTests/Internal/BridgeAPI/BridgeAPI+SessionCompletionHandlerTests.swift @@ -46,9 +46,11 @@ extension BridgeAPITests { func testInvokingAuthSessionCompletionHandlerFromHandlerWithInvalidURLWithoutError() { var url = URL(string: " ") + #if swift(>=5.9) if #available(iOS 17.0, *) { url = URL(string: " ", encodingInvalidCharacters: false) } + #endif var capturedSuccesses = [Bool]() var capturedErrors = [Error?]() let handler: SuccessBlock = { success, error in