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
This commit is contained in:
Zilin Zhang
2023-09-25 22:10:42 -07:00
committed by Facebook GitHub Bot
parent 51ae3301ba
commit de74c60d26
4 changed files with 14 additions and 3 deletions

View File

@@ -327,12 +327,14 @@ static FBSDKInternalUtility *_shared;
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;

View File

@@ -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:))

View File

@@ -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: [:])

View File

@@ -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