Error trapping Swift Google upload to Firebase code - ios

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}

Related

Silent notifications not working iOS Firebase

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 in opening UIDocumentPickerViewController

I am trying to present UIDocumentPickerViewController from my Viewcontroller. Sometimes I get error saying Could not communicate with a helper application.
The way I present my DocumentPickerViewController is:
BHFilePickerViewController *documentPicker = [[BHFilePickerViewController alloc]initWithDocumentTypes:types inMode:UIDocumentPickerModeImport];
documentPicker.filePickerDelegate = self;
documentPicker.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:documentPicker animated:true completion:nil];
Where, BHFilePickerViewController is my custom class of type UIDocumentPickerViewController.
When issue occurs I can see the log as
[DocumentManager] The view service did terminate with error: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo={Message=Service Connection Interrupted}
Remote view controller crashed with error: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo={Message=Service Connection Interrupted}. Trying to relaunch.
[u 571773A2-04B9-4EAB-A4AE-E0C629CB07AF:m (null)] [com.apple.DocumentManagerUICore.Service(1.0)] Connection to plugin interrupted while in use.
[DocumentManager] Failed to get the remote browser View Controller with error (Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service on pid 0 named com.apple.DocumentManagerUICore.Service.viewservice was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid." UserInfo={NSDebugDescription=The connection to service on pid 0 named com.apple.DocumentManagerUICore.Service.viewservice was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid.})
[DocumentManager] Remote view controller crashed with error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service on pid 0 named com.apple.DocumentManagerUICore.Service.viewservice was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid." UserInfo={NSDebugDescription=The connection to service on pid 0 named com.apple.DocumentManagerUICore.Service.viewservice was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid.}. Trying to relaunch.
Am I presenting it wrong way? What could you be improved?
Thank you in advance.

HTTP2 NSPOSIXErrorDomain Code=100 "Protocol error”

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

HTTP load failed (error code: -1005) iOS

In my app, I use Alamofire to fetch data from my server. For each time I fetch, 10 results will be sent from my server to my app. If I only post 3 requests or less at the same time, no any issue. If I post 5 or more requests at the same time, I received below error (1). After about 60s, I received below error (2). I am wondering this is my server issue or ?? Any suggestions? Thanks.
error(1) - 1005
2017-11-25 17:12:31.645624+0800 LeanCloudStarter[2044:84112] Task <520034AA-B195-4354-ADB6-3544C5907E22>.<69> HTTP load failed (error code: -1005 [4:-4])
2017-11-25 17:12:31.646056+0800 LeanCloudStarter[2044:83813] Task <520034AA-B195-4354-ADB6-3544C5907E22>.<69> finished with error - code: -1005
error(2) - 1001
2017-11-25 20:59:42.370155+0800 LeanCloudStarter[4098:180387] TIC TCP Conn Failed [110:0x600000172fc0]: 1:60 Err(60)
2017-11-25 20:59:42.370640+0800 LeanCloudStarter[4098:180387] Task <A951A3F1-B8B3-415B-9BBA-AFDF039A57C3>.<125> HTTP load failed (error code: -1001 [1:60])
2017-11-25 20:59:42.371383+0800 LeanCloudStarter[4098:180306] Task <A951A3F1-B8B3-415B-9BBA-AFDF039A57C3>.<125> finished with error - code: -1001

iOS GCDAsyncSocket Error: Domain=NSPOSIXErrorDomain Code=57

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.

Resources