We're using the Network.framework and send data between an iOS app and a macOS app. Works great. Until it doesn't.
When I stop using the iOS app for like 2-3 minutes the connections stops working.
The debug log of the macOS app says: 2020-12-01 22:40:40.274638+0100 Remote for Zoom[10750:497151] [] nwsocketgetinputframes [C4:1] recvmsg(fd 35, 9216 bytes) [61: Connection refused]
Can someone translate this into English? Tried the google traslator but...
On a more serious note, what is this and how to heal it? Does the 2-3 min pause as symptom / trigger of the above error message ring some bells?
Post
Replies
Boosts
Views
Activity
Context
I am trying to create a communication channel based on Bonjour NetService and URLSessionStreamTask to open the I/O stream.
I have the setup ready and I am able to connect with bonjour service and open I/O streams between mac and iOS app.
I am using swift codables for request and response, so communication is based on codable structs encoded as Data. I send a Request struct (by outputStream.write(data)) and wait for a response struct from mac app in input stream.
Problem
I am sending fetchUser request (after receiving response for loginUser), the mac app receives the request and writes the response without write failing (-1) but I'm not receiving the response in iOS app. (Although I received the response for previous loginUser request)
I'm not able to figure out where exactly the issue is. Attaching the code snippets here.
PS: I am noob at IO streams handling so a detailed response will be helpful. May be some sources where I can understand more about the topic.
Mac App code
let service: NetService = NetService(domain: "local.", type: "_my-app._tcp.", name: "test", port: 0)
service.delegate = self
service.publish(options: .listenForConnections)
//Writes response to connected output stream
	func send(response: HalloResponse) {
		do {
			let data = try encoder.encode(response)
			print("HalloServer: Response: \(String(describing: String(data: data, encoding: .utf8)))")
			if serviceDelegate.dataStream?.outputSteam.write(data: data) == -1 {
				print("HalloServer: send(response: HalloResponse) Write failied")
			}
		} catch {
			print("HalloServer: Exception in send(request: Request)")
		}
	}
//NetServiceDelegate
func netService(_ sender: NetService, didAcceptConnectionWith inputStream: InputStream, outputStream: OutputStream) {
		print("NetServiceDelegate: service - \(sender.name) inputStream - \(inputStream) outputStream \(outputStream)")
		self.inputStream = inputStream
		self.outputSteam = outputSteam
		self.inputStream.delegate = self
		self.outputSteam.delegate = self
		self.inputStream.schedule(in: .main, forMode: .default)
		self.inputStream.schedule(in: .main, forMode: .default)
		self.inputStream.open()
		self.inputStream.open()
	}
// StreamDelegate
func stream(_ aStream: Stream, handle eventCode: Stream.Event) {
		print("StreamDelegate: handle eventCode: \(eventCode.rawValue)")
		if inputStream == aStream {
			switch eventCode {
			case .hasBytesAvailable:
				var data = Data()
				guard inputStream.read(data: &data) > 0 else { return }
				print("HalloDataStream: Recieved data - \(String(describing: String(data: data, encoding: .utf8)))")
				let decoder = JSONDecoder()
				if let request = try? decoder.decode(Request.self, from: data) {
					delegate?.didReceive(request: request)
				}
				if let response = try? decoder.decode(HalloResponse.self, from: data) {
					delegate?.didReceive(response: response)
				}
			default: break
			}
		}
	}
iOS App code
serviceBrowser.searchForServices(ofType: "_my-app._tcp.", inDomain: "local.")
func connect(with service: NetService, completion: @escaping DeviceConnectionCompletion) {
		deviceCompletion = completion
		let config = URLSessionConfiguration.default
		config.requestCachePolicy = .reloadIgnoringLocalCacheData
		let session = URLSession(configuration: config, delegate: self, delegateQueue: .main)
		streamTask = session.streamTask(with: service)
		streamTask?.resume()
		streamTask?.captureStreams()
	}
	func send(request: Request) {
		do {
			let data = try encoder.encode(request)
			print("HalloClient: Request: \(String(describing: String(data: data, encoding: .utf8)))")
			if dataStream?.outputSteam.write(data: data) == -1 {
				print("HalloClient: send(request: Request) Write failied")
			}
		} catch {
			print("HalloClient: Exception in send(request: Request)")
		}
	}
// URLSessionStreamDelegate
func urlSession(
		_ session: URLSession,
		streamTask: URLSessionStreamTask,
		didBecome inputStream: InputStream,
		outputStream: OutputStream
	) {
		print("didBecomeInputStream:(NSInputStream *)inputStream outputStream: OutputStream")
		deviceCompletion?(true)
		self.inputStream = inputStream
		self.outputSteam = outputSteam
		self.inputStream.delegate = self
		self.outputSteam.delegate = self
		self.inputStream.schedule(in: .main, forMode: .default)
		self.inputStream.schedule(in: .main, forMode: .default)
		self.inputStream.open()
		self.inputStream.open()
	}
// StreamDelegate
	 func stream(_ aStream: Stream, handle eventCode: Stream.Event) {
		 // code exactly same as mac app delegate
	 }
Extensions on IO stream
extension InputStream {
	private var maxLength: Int { return 4096 }
	func read(data: inout Data) -> Int {
		var totalReadCount: Int = 0
		let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: maxLength)
		while hasBytesAvailable {
			let numberOfBytesRead = read(buffer, maxLength: maxLength)
			if numberOfBytesRead < 0, let error = streamError {
				print("Read Error: \(error)")
				break
			}
			data.append(buffer, count: numberOfBytesRead)
			totalReadCount += numberOfBytesRead
		}
		return totalReadCount
	}
}
extension OutputStream {
	@discardableResult
	func write(data: Data) -> Int {
		if streamStatus != .open {
			open()
		}
		let count = data.count
		let result = data.withUnsafeBytes {
			write($0.bindMemory(to: UInt8.self).baseAddress!, maxLength: count)
		}
		close()
		return result
	}
}
It would be really helpful if somebody can review my code and help me figure out the issue. I have a feeling that the issue is with stream open() and close(). Initially, nothing was working but adding open and close functions during write helped. Maybe I need a better way to fix this problem. PS: I had the same problem with CocoaAsyncSocket and I am not looking to use it or any other third party solution.
Since I've upgraded to Big Sur Xcode 10.3 which I need is crashed when I try to launch it. I reinstalled to no avail...
Process: Xcode [943]
Path: /Users/USER/Downloads/Xcode.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
Version: 10.3 (14492.2)
Build Info: IDEFrameworks-14492002000000000~2 (10G8)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Xcode [943]
User ID: 501
PlugIn Path: /Users/USER/Downloads/Xcode.app/Contents/Developer/usr/lib/libMainThreadChecker.dylib
PlugIn Identifier: libMainThreadChecker.dylib
PlugIn Version: ??? (64492.1)
Date/Time: 2020-11-19 13:23:03.155 +0100
OS Version: macOS 11.0.1 (20B29)
Report Version: 12
Bridge OS Version: 5.0.1 (18P2561)
Anonymous UUID: 3A5EAA65-D39F-FA97-D7F6-A9504FA39AEC
Time Awake Since Boot: 1100 seconds
System Integrity Protection: enabled
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXCBADACCESS (SIGBUS)
Exception Codes: KERNPROTECTIONFAILURE at 0x00007fff237a29b9
Exception Note: EXCCORPSENOTIFY
Termination Signal: Bus error: 10
Termination Reason: Namespace SIGNAL, Code 0xa
Terminating Process: exc handler [943]
VM Regions Near 0x7fff237a29b9:
_TEXT 7fff22c09000-7fff23600000 [ 10.0M] r-x/r-x SM=COW /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit-> TEXT 7fff23600000-7fff23800000 [ 2048K] r-x/rwx SM=PRV /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit
Submap 7fff23800000-7fff40000000 [456.0M] r--/rwx SM=PRV process-only VM submap
Application Specific Information:
/Users/tmiskiew/Downloads/Xcode.app/Contents/Developer/usr/lib/libMainThreadChecker.dylib
ProductBuildVersion: 10G8
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libMainThreadChecker.dylib 0x000000011ad0c069 swizzleImplementationFast + 115
1 libMainThreadChecker.dylib 0x000000011ad0bef0 addSwizzler + 165
2 libMainThreadChecker.dylib 0x000000011ad0baec libraryinitializer + 2937
3 dyld 0x000000010e5bfdf5 ImageLoaderMachO::doImageInit(ImageLoader::LinkContext const&) + 321
4 dyld 0x000000010e5c046d ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) + 29
5 dyld 0x000000010e5bad1a ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 492
6 dyld 0x000000010e5b8b82 ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 188
7 dyld 0x000000010e5b8c22 ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) + 82
8 dyld 0x000000010e5a96a2 dyld::runInitializers(ImageLoader*) + 82
9 dyld 0x000000010e5b4569 dlopeninternal + 609
10 libdyld.dylib 0x00007fff20354fd0 dlopeninternal(char const*, int, void*) + 177
11 libdyld.dylib 0x00007fff2034387e dlopen + 28
12 com.apple.dt.IDEFoundation 0x0000000104617487 IDEInitializeMainThreadChecker + 400
13 com.apple.dt.IDEFoundation 0x0000000104617e99 IDEInitialize + 1038
14 com.apple.dt.IDEKit 0x000000010526e3cd -[IDEApplicationController applicationWillFinishLaunching:] + 622
...
External Modification Summary:
Calls made by other processes targeting this process:
taskforpid: 0
threadcreate: 0
threadsetstate: 0
Calls made by this process:
taskforpid: 0
threadcreate: 0
threadsetstate: 0
Calls made by all processes on this machine:
taskforpid: 543
threadcreate: 0
threadsetstate: 0
VM Region Summary:
ReadOnly portion of Libraries: Total=1.0G resident=0K(0%) swappedoutorunallocated=1.0G(100%)
Writable regions: Total=872.0M written=0K(0%) resident=0K(0%) swappedout=0K(0%) unallocated=872.0M(100%)
VIRTUAL REGION
REGION TYPE SIZE COUNT (non-coalesced)
=========== ======= =======
Activity Tracing 256K 1
Dispatch continuations 128.0M 1
Foundation 16K 1
Kernel Alloc Once 8K 1
MALLOC 131.2M 32
MALLOC guard page 24K 4
MALLOCMEDIUM (reserved) 600.0M 5 reserved VM address space (unallocated)
STACK GUARD 56.0M 4
Stack 9752K 4
VMALLOCATE 916K 12
_CTF 759 1
DATA 35.0M 567
DATACONST 27.4M 340
_DATADIRTY 1829K 217
_FONTDATA 4K 1
_LINKEDIT 526.6M 77
OBJCRO 61.0M 1
_OBJCRW 2468K 2
_TEXT 530.4M 554
UNICODE 588K 1
mapped file 46.9M 10
shared memory 40K 4
=========== ======= =======
TOTAL 2.1G 1840
TOTAL, minus reserved VM space 1.5G 1840
Model: iMac20,2, BootROM 1554.50.3.0.0 (iBridge: 18.16.12561.0.0,0), 8 processors, 8-Core Intel Core i7, 3,8 GHz, 40 GB, SMC
Graphics: kHWAMDRadeonPro5700Item, AMD Radeon Pro 5700, spdisplayspciedevice, 8 GB
Memory Module: Slot 1 (Channel A / DIMM 1), 4 GB, DDR4, 2667 MHz, SK Hynix, HMA851S6DJR6N-VK
Memory Module: Slot 2 (Channel A / DIMM 0), 4 GB, DDR4, 2667 MHz, SK Hynix, HMA851S6DJR6N-VK
Memory Module: Slot 3 (Channel B / DIMM 1), 16 GB, DDR4, 2667 MHz, 0000, unknown
Memory Module: Slot 4 (Channel B / DIMM 0), 16 GB, DDR4, 2667 MHz, 0000, unknown
AirPort: spairportwirelesscardtypeairport_extreme (0x14E4, 0x7BF), wl0: Sep 11 2020 17:01:15 version 9.30.440.2.32.5.61 FWID 01-1d69e4b4
Bluetooth: Version 8.0.1f5, 3 services, 27 devices, 1 incoming serial ports
Network Service: Wi-Fi, AirPort, en1
USB Device: USB 3.1 Bus
USB Device: Apple T2 Bus
USB Device: Headset
USB Device: Ambient Light Sensor
USB Device: FaceTime HD Camera (Built-in)
USB Device: Apple T2 Controller
Thunderbolt Bus: iMac, Apple Inc., 58.2
I build a remote for zoom meetings. Since this allows the user to be far away from the Mac or Macbook I'm exploring using the iPhone as the microphone. Any ideas how this could be solved?
We build a remote type of app that consist of a macOS and iPhone part.
It relies on WiFi communication because Apple. Unfortunately iPhones sometimes switch from WiFi to Mobile and then the app communication is broken. Is there a solution for this? Can this been prevented? Any other real world solutions / suggestions?
Hi there
to offer the best user experience I'd like to:
Check whether the Wi-Fi / Mobile Internet on the iPhone are on or off. Is there an interface for that?
If they're on how much can I check connection wise? Maybe Wi-Fi is actually working, i.e. I can connect to the router but there is no internet connection.
Can someone please enlighten me how these cases can be handled? What interfaces are available? How precise can one get to help the user understand where the problem might lie?
Thomas
We all ask for a refund sometimes. I don’t know about you but I always provide a reason so the developer of the app can improve. Can someone tell me where I can find the refund reasons of my so I can better understand what people didn’t like about the app?
We wrote an app that uses MultipeerConnectivity to talk to macOS.
Now we want to expand that iOS app to talk to Microsoft Windows.
Is Bonjour still (the only) way to go in 2020?
What are the best libs for achieving this? Any recommendations?
I build an app using the official Zoom SDK with the intention to publish it in the Apple App Store for iOS.Apple rejected the app saying:Guideline 5.2.2 - LegalAlthough Zoom Video Communications, Inc. may allow the general public to use their service, we still require the documentary evidence that you have all the necessary rights or permissions to request, display, or distribute account information in your application.Next StepsTo resolve this issue, please attach documentary evidence in the App Review Information section in App Store Connect. In accordance with section 3.2(f) of the Apple Developer Program License Agreement, you acknowledge that submitting falsified or fraudulent documentation can result in the termination of your Apple Developer Program account and the removal of your apps from the App Store. Once Legal has reviewed your documentation and confirms its validity, we will proceed with the review of your app.I want to work with them to get this app published and I want to avoid endless feedback a review looks. And so replied in the resoltuin center that I don't understand how I can comply and who shall I ask for what written permission. I suggested that we could have a brief phone call. So far I'm waiting for Apple's reaction...From what I understand Apple wants me to go to Zoom to ask for written permission to use their SDK. Am I correct? (Imagine every developer that uses some publicly available SDK has to ask the publisher for written permission 😕 ). Or what exact steps are required to get this resolved?ThanksThomas
We developed a macOS app using the Zoom SDK and are unable to submit it to the Mac App Store.According to Apple Sandboxing is required for all applications, but apps in the Zoom SDK for macOS are not. What can we do? BTW, Apparently not even Zoom's own macOS client is in the App Store for the Mac. What can we do?The error message from Apple says:The App sandbox not enabled. The following executables must include the “com.apple.security.app-sandbox” entitlement with a Boolean value of true in the entitlements property list: “…/Contents/Frameworks/SDK_Transcode.app/Contents/MacOS/SDK_Transcode”,“…/Contents/Frameworks/airhost.app/Contents/MacOS/airhost”,“…/Contents/Frameworks/aomhost.app/Contents/MacOS/aomhost”Refer to App Sandbox page at https://developer.apple.com/documentation/security/app_sandboxfor more information on sandboxing your app.
We wrote an app using the zoom.us macOS SDK. Not that we wanted to release the new version we cannot export to Apple App StoreApp Store Connect Operation ErrorERROR ITMS-90511: “CFBundleIdentifier Collision. The Info.plist CFBundleIdentifier value ‘us.zoom.airhost’ of ‘OurApp macOS.app/Contents/Frameworks/airhost.app’ is already in use by another application.”Any suggestion what can be done here?Thomas
Hi therewe're in the process of developing an app that discovers and connects to different apple devices. Get we download from Apple the product pictures so that we discover an iPad Air then we Display an image of an iPad Air an not iPad Pro?ThanksThomas