Skip to content
Open
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
2 changes: 1 addition & 1 deletion build-ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ if [ "$IOS_PLAT" == "iphoneos" ] || [ "$IOS_PLAT" == "iphonesimulator" ]; then
SYS_NAME="iOS"
DEPLOYMENT_TARGET="$IOS_DEPLOYMENT_TARGET"
if [ -z "$DEPLOYMENT_TARGET" ]; then
DEPLOYMENT_TARGET="10.0"
DEPLOYMENT_TARGET="12.0"
FORCE_RESET_DEPLOYMENT_TARGET=YES
fi
elif [ "$IOS_PLAT" == "xros" ] || [ "$IOS_PLAT" == "xrsimulator" ]; then
Expand Down
4 changes: 1 addition & 3 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Honor visibility properties for all target types
cmake_policy(SET CMP0063 NEW)

include_directories( . ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include/public ${CMAKE_CURRENT_SOURCE_DIR}/include/public ${CMAKE_CURRENT_SOURCE_DIR}/include/mat ${CMAKE_CURRENT_SOURCE_DIR}/pal ${CMAKE_CURRENT_SOURCE_DIR}/utils ${CMAKE_CURRENT_SOURCE_DIR}/modules/exp ${CMAKE_CURRENT_SOURCE_DIR}/modules/dataviewer ${CMAKE_CURRENT_SOURCE_DIR}/modules/privacyguard ${CMAKE_CURRENT_SOURCE_DIR}/modules/liveeventinspector ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/Reachability ${CMAKE_CURRENT_SOURCE_DIR}/modules/cds ${CMAKE_CURRENT_SOURCE_DIR}/modules/signals ${CMAKE_CURRENT_SOURCE_DIR}/modules/sanitizer /usr/local/include )
include_directories( . ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include/public ${CMAKE_CURRENT_SOURCE_DIR}/include/public ${CMAKE_CURRENT_SOURCE_DIR}/include/mat ${CMAKE_CURRENT_SOURCE_DIR}/pal ${CMAKE_CURRENT_SOURCE_DIR}/utils ${CMAKE_CURRENT_SOURCE_DIR}/modules/exp ${CMAKE_CURRENT_SOURCE_DIR}/modules/dataviewer ${CMAKE_CURRENT_SOURCE_DIR}/modules/privacyguard ${CMAKE_CURRENT_SOURCE_DIR}/modules/liveeventinspector ${CMAKE_CURRENT_SOURCE_DIR}/modules/cds ${CMAKE_CURRENT_SOURCE_DIR}/modules/signals ${CMAKE_CURRENT_SOURCE_DIR}/modules/sanitizer /usr/local/include )

set(SRCS decorators/BaseDecorator.cpp
packager/BondSplicer.cpp
Expand Down Expand Up @@ -161,8 +161,6 @@ if(PAL_IMPLEMENTATION STREQUAL "CPP11")

list(APPEND SRCS
pal/posix/NetworkInformationImpl.mm
# TODO: this unit below needs to be deprecated and removed
../third_party/Reachability/ODWReachability.m
)
else()
list(APPEND SRCS
Expand Down
127 changes: 34 additions & 93 deletions lib/pal/posix/NetworkInformationImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "pal/NetworkInformationImpl.hpp"

#import <Network/Network.h>
#import "ODWReachability.h"

namespace PAL_NS_BEGIN {

Expand Down Expand Up @@ -67,12 +66,7 @@ virtual NetworkCost GetNetworkCost()
void UpdateCost(NetworkCost cost) noexcept;
std::string m_network_provider {};

// iOS 12 and newer
nw_path_monitor_t m_monitor = nil;

// iOS 11 and older
ODWReachability* m_reach = nil;
id m_notificationId = nil;
};

NetworkInformation::NetworkInformation(IRuntimeConfig& configuration) :
Expand All @@ -84,117 +78,64 @@ virtual NetworkCost GetNetworkCost()

NetworkInformation::~NetworkInformation() noexcept
{
if (@available(macOS 10.14, iOS 12.0, *))
{
if (m_isNetDetectEnabled)
{
nw_path_monitor_cancel(m_monitor);
}
}
else
if (m_isNetDetectEnabled)
{
if (m_isNetDetectEnabled)
{
[[NSNotificationCenter defaultCenter] removeObserver:m_notificationId];
[m_reach stopNotifier];
}
nw_path_monitor_cancel(m_monitor);
}
}

void NetworkInformation::SetupNetDetect()
{
auto weak_this = std::weak_ptr<NetworkInformation>(shared_from_this());

m_reach = [ODWReachability reachabilityForInternetConnection];
void (^block)(NSNotification*) = ^(NSNotification*)
m_monitor = nw_path_monitor_create();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should handle scenario where nw_path_monitor_create fails, and return nil - may be rare scenario but under system resource exhaustion?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is existing code, so probably not blocker here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API docs describe this return value as non-optional so it should never be nil - https://developer.apple.com/documentation/network/nw_path_monitor_create()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take that back, I checked the docs in Xcode and it does indeed look like this can be nil. I'm finding a hard time finding a reference to these docs online. Here's what it says:

/*!
 * @function nw_path_monitor_create
 *
 * @abstract
 *		Create a default path monitor, that will allow the enumeration of all available
 *		interfaces on the system.
 *
 * @result
 *		Returns an allocated nw_path_monitor_t object on success.
 *		Callers are responsible for deallocating using nw_release(obj) or [obj release].
 *		These objects support ARC.
 *		Returns NULL on failure. Fails due to invalid parameters.
 */
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
NW_RETURNS_RETAINED nw_path_monitor_t
nw_path_monitor_create(void);

nw_path_monitor_set_queue(m_monitor, dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0));
nw_path_monitor_set_update_handler(m_monitor, ^(nw_path_t path)
{
auto strong_this = weak_this.lock();
if (!strong_this)
{
return;
}

// NetworkCost information is not available until iOS 12.
// Just make the best guess here.
switch (m_reach.currentReachabilityStatus)
{
case NotReachable:
strong_this->UpdateType(NetworkType_Unknown);
strong_this->UpdateCost(NetworkCost_Unknown);
break;
case ReachableViaWiFi:
strong_this->UpdateType(NetworkType_Wifi);
strong_this->UpdateCost(NetworkCost_Unmetered);
break;
case ReachableViaWWAN:
strong_this->UpdateType(NetworkType_WWAN);
strong_this->UpdateCost(NetworkCost_Metered);
break;
}
};
block(nil); // Update the initial status.

if (@available(macOS 10.14, iOS 12.0, *))
{
m_monitor = nw_path_monitor_create();
nw_path_monitor_set_queue(m_monitor, dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0));
nw_path_monitor_set_update_handler(m_monitor, ^(nw_path_t path)
NetworkType type = NetworkType_Unknown;
NetworkCost cost = NetworkCost_Unknown;
nw_path_status_t status = nw_path_get_status(path);
bool connected = status == nw_path_status_satisfied || status == nw_path_status_satisfiable;
if (connected)
{
auto strong_this = weak_this.lock();
if (!strong_this)
if (nw_path_uses_interface_type(path, nw_interface_type_wifi))
{
return;
type = NetworkType_Wifi;
}

NetworkType type = NetworkType_Unknown;
NetworkCost cost = NetworkCost_Unknown;
nw_path_status_t status = nw_path_get_status(path);
bool connected = status == nw_path_status_satisfied || status == nw_path_status_satisfiable;
if (connected)
else if (nw_path_uses_interface_type(path, nw_interface_type_cellular))
{
if (nw_path_uses_interface_type(path, nw_interface_type_wifi))
{
type = NetworkType_Wifi;
}
else if (nw_path_uses_interface_type(path, nw_interface_type_cellular))
{
type = NetworkType_WWAN;
}
else if (nw_path_uses_interface_type(path, nw_interface_type_wired))
{
type = NetworkType_Wired;
}
cost = nw_path_is_expensive(path) ? NetworkCost_Metered : NetworkCost_Unmetered;
if (@available(macOS 10.15, iOS 13.0, *))
type = NetworkType_WWAN;
}
else if (nw_path_uses_interface_type(path, nw_interface_type_wired))
{
type = NetworkType_Wired;
}
cost = nw_path_is_expensive(path) ? NetworkCost_Metered : NetworkCost_Unmetered;
if (@available(macOS 10.15, iOS 13.0, *))
{
if (nw_path_is_constrained(path))
{
if (nw_path_is_constrained(path))
{
cost = NetworkCost_Roaming;
}
cost = NetworkCost_Roaming;
}
}
strong_this->UpdateType(type);
strong_this->UpdateCost(cost);
});
nw_path_monitor_start(m_monitor);

// nw_path_monitor_start will invoke the callback for once. So if
// we don't want to listen for changes, we can just start the
// monitor and stop it right away.
if (!m_isNetDetectEnabled)
{
nw_path_monitor_cancel(m_monitor);
}
}
else if (m_isNetDetectEnabled)
strong_this->UpdateType(type);
strong_this->UpdateCost(cost);
});
nw_path_monitor_start(m_monitor);

// nw_path_monitor_start will invoke the callback for once. So if
// we don't want to listen for changes, we can just start the
// monitor and stop it right away.
if (!m_isNetDetectEnabled)
{
m_notificationId =
[[NSNotificationCenter defaultCenter]
addObserverForName: kNetworkReachabilityChangedNotification
object: nil
queue: nil
usingBlock: block];
[m_reach startNotifier];
nw_path_monitor_cancel(m_monitor);
}
}

Expand Down
113 changes: 0 additions & 113 deletions tests/unittests/obj-c/ODWReachabilityTests.mm

This file was deleted.

4 changes: 0 additions & 4 deletions tests/unittests/unittests-ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
16CC10702D4D58DA00C03295 /* ODWReachabilityTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 16CC106F2D4D58DA00C03295 /* ODWReachabilityTests.mm */; };
430102E5235E660F00836D50 /* iOSWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 430102E4235E660F00836D50 /* iOSWrapper.mm */; };
431EFE50233EBE54002FCC18 /* HttpClientTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 431EFE2A233EBE53002FCC18 /* HttpClientTests.cpp */; };
431EFE51233EBE54002FCC18 /* LoggerTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 431EFE2B233EBE53002FCC18 /* LoggerTests.cpp */; };
Expand Down Expand Up @@ -117,7 +116,6 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
16CC106F2D4D58DA00C03295 /* ODWReachabilityTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = ODWReachabilityTests.mm; path = "obj-c/ODWReachabilityTests.mm"; sourceTree = "<group>"; };
430102E4235E660F00836D50 /* iOSWrapper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = iOSWrapper.mm; path = ../../common/iOSWrapper.mm; sourceTree = "<group>"; };
431EFE1E233EBDF2002FCC18 /* libunittests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libunittests.a; sourceTree = BUILT_PRODUCTS_DIR; };
431EFE2A233EBE53002FCC18 /* HttpClientTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HttpClientTests.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -203,7 +201,6 @@
431EFE15233EBDF2002FCC18 = {
isa = PBXGroup;
children = (
16CC106F2D4D58DA00C03295 /* ODWReachabilityTests.mm */,
43BD496F26B8B0C300EC3C0C /* EventPropertiesDecoratorTests.cpp */,
437C72F024D2286F0046F545 /* ODWLogConfigurationTests.mm */,
437C72EE24D21ACE0046F545 /* ODWSemanticContextTests.mm */,
Expand Down Expand Up @@ -436,7 +433,6 @@
431EFEA7233EC590002FCC18 /* HttpDeflateCompressionTests.cpp in Sources */,
431EFEB3233EC590002FCC18 /* OfflineStorageTests.cpp in Sources */,
431EFEB8233EC590002FCC18 /* TaskDispatcherCAPITests.cpp in Sources */,
16CC10712D4D58DA00C03295 /* ODWReachabilityTests.mm in Sources */,
437C72ED24D0C5D70046F545 /* ODWEventPropertiesTests.mm in Sources */,
431EFEB6233EC590002FCC18 /* RouteTests.cpp in Sources */,
431EFEA8233EC590002FCC18 /* HttpRequestEncoderTests.cpp in Sources */,
Expand Down
Loading
Loading