Skip to content

Commit c61e171

Browse files
author
James Hutchby
authored
Merge pull request #27 from grandcentrix/fix-scan-stability
Improve scan stability
2 parents bc1d5f7 + 0df8ffd commit c61e171

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

GCXMulticastDNSKit.xcodeproj/project.pbxproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
isa = PBXProject;
157157
attributes = {
158158
LastSwiftUpdateCheck = 0820;
159-
LastUpgradeCheck = 1020;
159+
LastUpgradeCheck = 1250;
160160
ORGANIZATIONNAME = "grandcentrix GmbH";
161161
TargetAttributes = {
162162
68FF3C161E24DDDF00A482A8 = {
@@ -278,6 +278,7 @@
278278
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
279279
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
280280
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
281+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
281282
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
282283
CLANG_WARN_STRICT_PROTOTYPES = YES;
283284
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -303,7 +304,7 @@
303304
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
304305
GCC_WARN_UNUSED_FUNCTION = YES;
305306
GCC_WARN_UNUSED_VARIABLE = YES;
306-
IPHONEOS_DEPLOYMENT_TARGET = 10.2;
307+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
307308
MTL_ENABLE_DEBUG_INFO = YES;
308309
ONLY_ACTIVE_ARCH = YES;
309310
SDKROOT = iphoneos;
@@ -341,6 +342,7 @@
341342
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
342343
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
343344
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
345+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
344346
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
345347
CLANG_WARN_STRICT_PROTOTYPES = YES;
346348
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -360,7 +362,7 @@
360362
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
361363
GCC_WARN_UNUSED_FUNCTION = YES;
362364
GCC_WARN_UNUSED_VARIABLE = YES;
363-
IPHONEOS_DEPLOYMENT_TARGET = 10.2;
365+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
364366
MTL_ENABLE_DEBUG_INFO = NO;
365367
SDKROOT = iphoneos;
366368
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";

GCXMulticastDNSKit.xcodeproj/xcshareddata/xcschemes/GCXMulticastDNSKit.xcscheme

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1020"
3+
LastUpgradeVersion = "1250"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -27,6 +27,15 @@
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
2929
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<MacroExpansion>
31+
<BuildableReference
32+
BuildableIdentifier = "primary"
33+
BlueprintIdentifier = "68FF3C161E24DDDF00A482A8"
34+
BuildableName = "GCXMulticastDNSKit.framework"
35+
BlueprintName = "GCXMulticastDNSKit"
36+
ReferencedContainer = "container:GCXMulticastDNSKit.xcodeproj">
37+
</BuildableReference>
38+
</MacroExpansion>
3039
<Testables>
3140
<TestableReference
3241
skipped = "NO">
@@ -39,17 +48,6 @@
3948
</BuildableReference>
4049
</TestableReference>
4150
</Testables>
42-
<MacroExpansion>
43-
<BuildableReference
44-
BuildableIdentifier = "primary"
45-
BlueprintIdentifier = "68FF3C161E24DDDF00A482A8"
46-
BuildableName = "GCXMulticastDNSKit.framework"
47-
BlueprintName = "GCXMulticastDNSKit"
48-
ReferencedContainer = "container:GCXMulticastDNSKit.xcodeproj">
49-
</BuildableReference>
50-
</MacroExpansion>
51-
<AdditionalOptions>
52-
</AdditionalOptions>
5351
</TestAction>
5452
<LaunchAction
5553
buildConfiguration = "Debug"
@@ -70,8 +68,6 @@
7068
ReferencedContainer = "container:GCXMulticastDNSKit.xcodeproj">
7169
</BuildableReference>
7270
</MacroExpansion>
73-
<AdditionalOptions>
74-
</AdditionalOptions>
7571
</LaunchAction>
7672
<ProfileAction
7773
buildConfiguration = "Release"

GCXMulticastDNSKit/Discovery.swift

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,13 @@ extension Discovery {
216216
}
217217
}
218218

219-
/// stops all search and resolve operations, nil out delegates to circumvent http://www.openradar.me/28943305
219+
/// stops all search and resolve operations
220220
private func stopSearchingAndResolving() {
221-
_ = items?.map {
221+
items?.forEach {
222222
$0.netServiceBrowser.stop()
223+
// set delegate to nil to circumvent http://www.openradar.me/28943305
223224
$0.netServiceBrowser.delegate = nil
224-
_ = $0.netServices.map {
225+
$0.netServices.forEach {
225226
$0.stop()
226227
$0.delegate = nil
227228
}
@@ -285,6 +286,28 @@ extension Discovery: NetServiceBrowserDelegate {
285286
public func netServiceBrowser(_ browser: NetServiceBrowser, didNotSearch errorDict: [String: NSNumber]) {
286287
guard let item = item(serviceBrowser: browser) else { return }
287288

289+
if let errorCode = errorDict[NetService.errorCode] as? Int {
290+
if let netServiceError = NetService.ErrorCode(rawValue: errorCode) {
291+
switch netServiceError {
292+
// when unknown error is received, browsing has stopped and must be restarted.
293+
// this happens when the app suspends/resumes
294+
case .unknownError:
295+
// notify the caller that all existing discovered services have dissapeared
296+
for service in item.netServices {
297+
notifyDiscoveryServiceDidDisappear(service: DiscoveryService(configuration: item.configuration, netService: service))
298+
}
299+
// immediately restart discovery
300+
self.startDiscovery()
301+
302+
// don't send .browsingFailure
303+
return
304+
default:
305+
break
306+
}
307+
}
308+
}
309+
310+
// other failures should be returned because it could be a configuration error
288311
notifyDiscoveryDidFail(configuration: item.configuration, error: .browsingFailure)
289312
}
290313

0 commit comments

Comments
 (0)