Skip to content

Commit

Permalink
Fix Build issue in XCode 14
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Zilin Zhang authored and facebook-github-bot committed Sep 26, 2023
1 parent 51ae330 commit de74c60
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
8 changes: 5 additions & 3 deletions FBSDKCoreKit/FBSDKCoreKit/FBSDKInternalUtility.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions FBSDKCoreKit/FBSDKCoreKit/Profile+Loading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:))
Expand Down
4 changes: 4 additions & 0 deletions FBSDKCoreKit/FBSDKCoreKitTests/AppLinkNavigationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [:])
Expand Down Expand Up @@ -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: [:])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit de74c60

Please sign in to comment.