This is a weird one. I'm using GCDAsyncSocket and when I'm using the iOS simulator sometimes I can connect and send, no problem but sometimes when I try to connect and send something (writeData) I get the following error:
didDisconnect Error Domain=NSPOSIXErrorDomain Code=57 "The operation couldn’t be completed. Socket is not connected"
What is odd, I cannot predict when this will happen. Also when I check to see isConnected, that returns true.
Here is the code (SWIFT):
var sendBytes:[Byte] = [0x0, 0x1, 0x2, 0x3]
var msgData = NSData(bytes: sendBytes, length: sendBytes.count)
socket.writeData(msgData, withTimeout: -1.0, tag: 0)
socket.readDataWithTimeout(-1.0, tag: 0)
The socket(didConnectToHost) callback fired with no issues and correct address and port returned, but when I try the above code to writeData to socket, I get the above error.
Any ideas why this would be happening randomly.
Related
We are writing an iOS app that uploads data to Google Firebase storage. We use the code below to upload text data to the location we specify. It works fine, except when we are not connected to the internet.
For the case of not being connected to the internet, we are having trouble trapping and handling the error. As far as we can tell, the delegate is never called (MyFirebaseProtocol_UploadTextComplete doesn't fire until much later, perhaps after a timeout) , and it just tries to upload repeatedly. If we are connected to the Mac and watching the debug window, it continuously generates errors in a loop, indefinitely. These certainly look like they are intended to be trappable (class names like NSErrorFailingURLStringKey, and helpful error messages and codes), but so far we are unable to trap them as they occur.
We are relatively new at swift, but is there some syntax, something like exception handling, that will allow us to trap and handle these errors, rather than just loop indefinitely?
Thanks!
func UploadTextFile(filepath : String, text: String, delegate : MyFirebaseProtocol)
{
let storage = Storage.storage()
let storageRef = storage.reference()
let textfileref = storageRef.child(filepath)
let data: Data? = text.data(using: .utf8)
textfileref.putData(data!, metadata: nil)
{
(metadata, error) in
delegate.MyFirebaseProtocol_UploadTextComplete(error: error)
}
}
Error messages in Xcode debug window:
2022-01-20 15:15:38.553528-0500 GarmentTest[431:60410] Connection 1: received failure notification
2022-01-20 15:15:38.553552-0500 GarmentTest[431:60410] Connection 1: failed to connect 1:50, reason -1
2022-01-20 15:15:38.553564-0500 GarmentTest[431:60410] Connection 1: encountered error(1:50)
2022-01-20 15:15:38.555426-0500 GarmentTest[431:60410] Connection 2: received failure notification
2022-01-20 15:15:38.555442-0500 GarmentTest[431:60410] Connection 2: failed to connect 1:50, reason -1
2022-01-20 15:15:38.555452-0500 GarmentTest[431:60410] Connection 2: encountered error(1:50)
2022-01-20 15:15:38.557057-0500 GarmentTest[431:60410] Task .<1> HTTP load failed, 0/0 bytes (error code: -1009 [1:50])
2022-01-20 15:15:38.557104-0500 GarmentTest[431:60410] Task <1D0E3033-5A15-4435-AF3D-99A06EAB4C3C>.<2> HTTP load failed, 0/0 bytes (error code: -1009 [1:50])
2022-01-20 15:15:38.557485-0500 GarmentTest[431:60410] Connection 3: received failure notification
2022-01-20 15:15:38.557544-0500 GarmentTest[431:60410] Connection 3: failed to connect 1:50, reason -1
2022-01-20 15:15:38.557664-0500 GarmentTest[431:60410] Connection 3: encountered error(1:50)
2022-01-20 15:15:38.558844-0500 GarmentTest[431:60268] Task .<1> finished with error [-1009] Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={_kCFStreamErrorCodeKey=50, NSUnderlyingError=0x280374a80 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask .<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask .<1>"
), NSLocalizedDescription=The Internet connection appears to be offline., NSErrorFailingURLStringKey=https://firebasestorage.googleapis.com/v0/b/garmenttest-8897e.appspot.com/o/Snapshots%2FAn%2FAn_20220120_151528_Relaxed_Center_Image_1B.png?uploadType=resumable&name=Snapshots%2FAn%2FAn_20220120_151528_Relaxed_Center_Image_1B.png, NSErrorFailingURLKey=https://firebasestorage.googleapis.com/v0/b/garmenttest-8897e.appspot.com/o/Snapshots%2FAn%2FAn_20220120_151528_Relaxed_Center_Image_1B.png?uploadType=resumable&name=Snapshots%2FAn%2FAn_20220120_151528_Relaxed_Center_Image_1B.png, _kCFStreamErrorDomainKey=1}
I am relatively new to Swift and am having trouble parsing the result of a GraphQL API call.
I see the result within the 'failure()' declaration is of the type NSError and I'm basically trying to access it if it is a 'failure' and then access the NSError keys. The result is:
failure(Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={NSUnderlyingError=0x282232700 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={NSErrorPeerAddressKey=<CFData 0x280e54b40 [0x1faa4fcf0]>{length = 16, capacity = 16, bytes = 0x1002005036d7fb9f0000000000000000}, _kCFStreamErrorCodeKey=-4, _kCFStreamErrorDomainKey=4}}, NSErrorFailingURLStringKey=http://staging.mysite.com/api/, NSErrorFailingURLKey=http://staging.mysite.com/api/v2/, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-4, NSLocalizedDescription=The network connection was lost.})
I get the below information by using:
print("\(result)")
Result is an object of type Result<GraphQLResult<Data>, Error>. There are methods to get errors but this result apparently isn't thrown as a GraphQL Error. The error catch I'm using is:
if let firstError = try? result.get().errors?.first {
completion([], [], firstError)
return
}
It passes this check so it is just interpreting it as a normal data result. My question is how do I parse this information?
My thinking is that I need to check if it is a failure, then unwrap it from the 'failure' type and then can treat the enclosed info as an NSError object. I can't use 'contains' since it's not a String. There is a get() method on result that allows you to result.get().data or result.get().error but neither return anything in this case.
Any help on how I can parse this information would be greatly appreciated. Thanks!
Result is a generic swift enumeration, which has two states: success or failure.
To get the error from the failure one must use a switch statement, for eg:
switch result {
case .failure(let error):
//Handle error here
default:
break
}
More on the Result enumeration here: https://developer.apple.com/documentation/swift/result.
When sending silent-notifications from firebase-admin cloud sdk (from firebase functions), I can see it is received since my console is printing some cryptic message but doens't actually run the logic in the method.
Here is the payload being sent:
message.apns = {
payload: {
aps : {
'content-available' : true
}
},
data: {
text: 'message'
}
};
Here is the log being printed in my console (my device is connected to my computer and running xcode on debug).
2020-03-18 20:07:44.687628+0200[2434:580744] [] nw_read_request_report [C3] Receive failed with error "Software caused connection abort"
2020-03-18 20:07:44.687895+0200[2434:580744] [] nw_read_request_report [C2] Receive failed with error "Software caused connection abort"
2020-03-18 20:07:44.690177+0200[2434:580744] [] nw_read_request_report [C3] Receive failed with error "Software caused connection abort"
However, it seems like something is blocking it from actually working and calling the relevant app delegate methods.
Has anyone run into this issue before?
Super cryptic and not really sure how to handle.
Thanks!
Error Domain=NSPOSIXErrorDomain Code=100 "Protocol error"
UserInfo={_NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask
<3EEC44C3-80A3-47B1-A0FD-C5DAD842FAAE>.<2>,
_kCFStreamErrorDomainKey=1, NSErrorPeerAddressKey={length = 16, capacity = 16, bytes =
0x100201bb34d5b9460000000000000000}
I recently switched my server and when I try to get a response am getting this error. I tried changing the header but it didn't work for me. It is working fine when I tried in postman and android
I am trying to retrieve PDF content from URL which also has authentication challenge. After returning completionHandler with user credentials to URLAuthenticationChallengedelegate method, I am finally getting below error. This happens only in iOS 9.x versions, but works fine in iOS 10.x.
Error Domain=NSPOSIXErrorDomain Code=100 "Protocol error" UserInfo={NSErrorPeerAddressKey=<CFData 0x7fae60e1e340 [0x1133aaa40]>{length = 16, capacity = 16, bytes = 0x100201bbb818161f0000000000000000}, _kCFStreamErrorCodeKey=100, _kCFStreamErrorDomainKey=1}
I also tried adding NSAppTransportSecurity settings NSTemporaryExceptionMinimumTLSVersion TLSv1.1 to the info.plist and tried to set HeaderField's, but no use.