My program is shown in following.
I want to get the dataTask session's error code working in background, but I haven't achieved it.
let config:URLSessionConfiguration = URLSessionConfiguration.background(withIdentifier: "abcd")
self.session = URLSession(configuration: config, delegate: nil, delegateQueue: nil)
let task: URLSessionDataTask = session!.dataTask(with: myRequest as URLRequest)
task.resume()
In the program above, there isn't any parameter with error information, so I rewrite it as following.
But when I run the following program, the exception error happens.
By the way, about the following program, it can be run successfully when URLSession is configured as normal session, but when URLSession is configured as background session as following, the exception error happens when it's run.
Anyone can give me some advice?
Thanks a lot!
let config:URLSessionConfiguration = URLSessionConfiguration.background(withIdentifier: "abcd")
self.session = URLSession(configuration: config, delegate: nil, delegateQueue: nil)
let task: URLSessionDataTask = session!.dataTask(with: myRequest as URLRequest) { (data, response, error) in
if let response = response as? HTTPURLResponse {
NSLog("response.statusCode = \(response.statusCode)")
}
}
task.resume()
Post not yet marked as solved
Hi Apple Team,
I have to do some such functionality in my applications that when application is in background, I have to upload the entire gallery assets of the iphone to a server (if the user has given permission to upload). I have come to a point where my background processing is not running for more than 28-30 seconds. And my process is such that I pick up the asset one by one from the gallery and process it and put it in a single task for uploading to the background thread. All this happens in a loop and photos are uploaded one after the other untill 28-30 seconds(in background). As I have also got my app registered for background processing and also coding is running from all standard process according to apple documentation.
So I have to ask you something about background processing, my questions are as follows:
1: What is the maximum duration for background processing and background uploading? What if I want to increase the duration of background processing in my app?
2: Does Apple extend the background processing time for certain category of apps, if it does, then please mention those categories(Or share some links).
3: As my application is built for a particular organization(they upload their all photos), I need maximum background upload limit, is there any way Apple provides for that? if yes, could you please share sample code base or links.
4: Some applications like Google Photos etc. upload in the background for more than 30 seconds, is there a standard procedure that I can achieve as well?
5: If there is any framework provided by Apple to do this work then please mention it.
Thanks, I am waiting for your kind reply.
I am working on some study in sending the data from iphone to server, and I want to keep the communication even when my program is working on the background mode.
For the details, when my program monitors the beacon' signal with special UUID by Corelocation( in other words, the iphone is taken into the beacon'region), then in Corelocation's handling function, the dataTask of URLSession will be excuted to forward the BLE signal's information to server.
Because the beacon sends the BLE signal periodically and continuously, I think the data will be sent from iphone to sever with my program continuously.
But now, my experiment result is, when I change the application into background:
-sometimes, the dataTask can be kept for several hours or one or two days without any problem
-sometimes, the dataTask will be stopped and after several minutes, it will be restarted automatically (really confusing). And in this case, I find the BLE monitoring program is kept to work, only the dataTask communication has been stopped
I want to know the reason and the dataTask's action condition of the above phenomenon such as keeping or stoping or restarting the communication.
Is there any method to keep the communication between the iphone and server without any interruption?
Thanks a lot!
Post not yet marked as solved
Hello
We are developing our own iOS Network Extensions-based VPN and it has an HTTP proxy in the VPN.
In addition, we also use PAC (Proxy auto-configuration) script to configure what kind of HTTP/HTTPS traffic should route to our proxy in the VPN.
However, we get this kind of message "Received XPC error Connection invalid for message type 3 kCFNetworkAgentXPCMessageTypePACQuery" randomly on iOS 15.5.
We have not been aware of any weird behavior of iOS based on the error message. We are afraid of this error message is caused by our VPN solution.
Is there any suggestion that should consider or follow to fix this error?
Post not yet marked as solved
finished with error [-1001] Error Domain=NSURLErrorDomain Code=-1001 “The request timed out.” UserInfo={_kCFStreamErrorCodeKey=-2102, NSUnderlyingError=0x282fbd800 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 “(null)” UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <7060BA29-10BA-40C9-91AB-DCA082E5F038>.<235>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
“LocalDataTask <7060BA29-10BA-40C9-91AB-DCA082E5F038>.<235>”
),NSLocalizedDescription=The request timed out., NSErrorFailingURLStringKey=<xyz.com>, NSErrorFailingURLKey=<xyz.com>, _kCFStreamErrorDomainKey=4}
getting this issue in some rare scenario, unable to find solution for this? anyone can help to resolve this?
because of this issue some times app stucks with loader screen and unable to work further.
I just replaced our server url with <xyz.com>.
I have checked with iPad 3rd generation.
Post not yet marked as solved
I am using URLSessionConfiguration.background and uploadTask to upload a file from an iOS app.
request.httpMethod = "POST"
request.setValue("application/octect-stream", forHTTPHeaderField: "Content-Type")
let task = uploadURLSession.uploadTask(with: request, fromFile: fileURL)
I'd like to understand how to manage the error handling.
How the http errors 4xx or 5xx are handled by the URLSession.uploadTask?
Post not yet marked as solved
I want to use URLCache to make data (e.g. User, Session, Privileges objects) available when offline. I think it is better to manually saving data in file or UserDefaults because it will fit seamlessly with existing code that load stuff from URLs and without extra code.
One of my concern is this. In URLCache documentation - https://developer.apple.com/documentation/foundation/urlcache, it says:
Note
In iOS, the on-disk cache may be purged when the system runs low on disk space, but only when your app is not running. I don't want my on-disk cache to get purged on low disk space.
I browse around and see URLCache has a new initializer in iOS 13 that accepts a directory url for on-disk cache.
convenience init(memoryCapacity: Int, diskCapacity: Int, directory: URL? = nil)
From my understanding, Caches directory gets purged on low disk space.
From File System Programming Guide - https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html:
In iOS 5.0 and later, the system may delete the Caches directory on rare occasions when the system is very low on disk space. This will never occur while an app is running. However, be aware that restoring from backup is not necessarily the only condition under which the Caches directory can be erased. So, my question is, if I pass a URL that is not a Caches directory URL. Will my on-disk cache survive the low memory purge? If not, is there any other way to achieve it?
AppVariant: 1:iPhone12,3:13
Code Type: ARM-64 (Native)
Role: Foreground
Parent Process: launchd [1]
Date/Time: 2022-04-17 12:26:31.2123 +0800
Launch Time: 2022-04-17 12:26:21.7178 +0800
OS Version: iPhone OS 14.2 (18B92)
Release Type: User
Baseband Version: 2.02.04
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 38
Thread 38 name:
Thread 38 Crashed:
0 libsystem_kernel.dylib 0x00000001b884f414 __pthread_kill + 8
1 libsystem_pthread.dylib 0x00000001d4d67b40 pthread_kill + 272 (pthread.c:1388)
2 libsystem_c.dylib 0x0000000194c74b74 abort + 104 (abort.c:110)
3 libsystem_malloc.dylib 0x000000019acfa49c malloc_vreport + 560 (malloc_printf.c:183)
4 libsystem_malloc.dylib 0x000000019acfa740 malloc_zone_error + 104 (malloc_printf.c:219)
5 libsystem_malloc.dylib 0x000000019acdfab0 szone_free + 464 (magazine_malloc.c:0)
6 CoreFoundation 0x000000018b8ed638 __CFStringDeallocate + 192 (CFString.c:1168)
7 CoreFoundation 0x000000018b8ce104 _CFRelease + 248 (CFRuntime.c:2126)
8 CoreFoundation 0x000000018b82f78c -[__NSArrayI dealloc] + 80 (NSCollectionAux.h:70)
9 CoreFoundation 0x000000018b832e60 -[__NSDictionaryI dealloc] + 156 (NSCollectionAux.h:48)
10 CFNetwork 0x000000018bfc5d18 invocation function for block in __CFURLCache::CreateAndStoreCacheNode(__CFURLCacheNode*, _CFCachedURLResponse const*, __CFString const*, _CFURLRequest const*, void const*, bool, bool&) + 928 (AutoTypes.h:36)
11 libdispatch.dylib 0x000000018b552fb8 _dispatch_block_async_invoke2 + 148 (queue.c:527)
12 libdispatch.dylib 0x000000018b544db0 _dispatch_client_callout + 20 (object.m:559)
13 libdispatch.dylib 0x000000018b54c10c _dispatch_lane_serial_drain + 580 (inline_internal.h:2548)
14 libdispatch.dylib 0x000000018b54cc90 _dispatch_lane_invoke + 460 (queue.c:3862)
15 libdispatch.dylib 0x000000018b556d78 _dispatch_workloop_worker_thread + 708 (queue.c:6601)
16 libsystem_pthread.dylib 0x00000001d4d68804 _pthread_wqthread + 276 (pthread.c:2206)
17 libsystem_pthread.dylib 0x00000001d4d6f75c start_wqthread + 8
Thread 38 crashed with ARM Thread State (64-bit):
x0: 0x0000000000000000 x1: 0x0000000000000000 x2: 0x0000000000000000 x3: 0x0000000000000000
x4: 0x0000000000000000 x5: 0x0000000000000000 x6: 0x0000000000000001 x7: 0x0000000000000010
x8: 0x00000000000005b9 x9: 0xcde6b451acd55cca x10: 0xcccccccccccccccd x11: 0x000000000000000a
x12: 0x0000000000000000 x13: 0x0000000000000039 x14: 0x0000000086c24000 x15: 0x00000001eb0d1b80
x16: 0x0000000000000148 x17: 0x000000016ce27000 x18: 0x0000000000000000 x19: 0x0000000000000006
x20: 0x000000000000cd03 x21: 0x000000016ce270e0 x22: 0x000000016ce26400 x23: 0x000000012957c000
x24: 0x0000000000000000 x25: 0x0000000000000000 x26: 0x000000016b36bc8a x27: 0x000000016ce27000
x28: 0x00000002825710a0 fp: 0x000000016ce26310 lr: 0x00000001d4d67b40
sp: 0x000000016ce262f0 pc: 0x00000001b884f414 cpsr: 0x40000000
esr: 0x56000080 Address size fault
Our app has "allow arbitrary loads" in the "App Transport Security Settings" and generally allows both "http" and "https" connections. I want to restrict basic authentication usage to secure connections only, what is the best way to do that?
I have URLSessionTaskDelegate's:
func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
where I can put the relevant logic, but how do I check if the connection attempt in question is happening over TLS or not? I can check task.currentRequest.url scheme being "http" vs "https", and port being nil vs 80 vs 443, but I hope there is a more robust check.
Post not yet marked as solved
https://developer.apple.com/documentation/foundation/urlcache
has this:
"Although URLCache instance methods can safely be called from multiple execution contexts at the same time, be aware that methods like cachedResponse(for:) and storeCachedResponse(_:for:) have an unavoidable race condition when attempting to read or write responses for the same request."
What does it mean "unavoidable"? If I put a lock (mutex / NSLock, or similar) in my wrappers on top of "cachedResponse" / "storeCachedResponse" would that avoid the mentioned race condition?
Also, what do they mean by "the same request"? A few examples below:
let url = URL(string: "https://www.apple.com")!
let req1 = URLRequest(url: url)
let req2 = req1 // perhaps "the same"
let req3 = URLRequest(url: url) // "the same"?
let req4 = URLRequest(url: req1.url!) // "the same"?
let req5 = URLRequest(url: url, cachePolicy: req1.cachePolicy, timeoutInterval: req1.timeoutInterval) // "the same"?
let req6 = URLRequest(url: url, cachePolicy: req1.cachePolicy, timeoutInterval: 1234) // "the same"?
let req7 = URLRequest(url: url, cachePolicy: .reloadIgnoringCacheData, timeoutInterval: req1.timeoutInterval) // "the same"?
assert(req1 == req2)
assert(req1 == req3)
assert(req1 == req4)
assert(req1 == req5)
assert(req1 == req6) // this is ok
assert(req1 == req7) // this fails
Post not yet marked as solved
Report
I have an application that apparently crashed for one of my users. Does anyone have any idea what might have caused this crash?
I tried
Reproducing the bug, but I had no success. I don't even know what use case would cause such a crash
Looking into some other posts with similar problems, but couldn't find anything close to this issue
In the next section, I provided you with some information that might be useful. If anything else is needed, feel free to let me know.
Crash details
Date
May 3, 2022, 6:02:02 PM
Device
iPhone 11 - iOS 15.4.1
Stack trace
Crashed: com.apple.CFNetwork.Connection
0 libsystem_kernel.dylib 0x7b78 __pthread_kill + 8
1 libsystem_pthread.dylib 0x73bc pthread_kill + 268
2 libsystem_c.dylib 0x2051c abort + 168
3 libsystem_malloc.dylib 0x1ca04 _malloc_put + 550
4 libsystem_malloc.dylib 0x1cc9c malloc_zone_error + 100
5 libsystem_malloc.dylib 0x170dc nanov2_allocate_from_block + 568
6 libsystem_malloc.dylib 0x16164 nanov2_allocate + 128
7 libsystem_malloc.dylib 0x16080 nanov2_malloc + 64
8 libsystem_malloc.dylib 0x6020 _malloc_zone_malloc + 156
9 libsystem_blocks.dylib 0x1630 _Block_copy + 64
10 libdispatch.dylib 0x1e2c _dispatch_Block_copy + 32
11 libdispatch.dylib 0x3bf8 _dispatch_block_create + 160
12 libdispatch.dylib 0x71e4 dispatch_block_create_with_qos_class + 256
13 libnetwork.dylib 0xbdac8 nw_connection_async_on_queue + 88
14 libnetwork.dylib 0xe35c0 nw_connection_report_state_with_handler_on_nw_queue + 1136
15 libnetwork.dylib 0xe3e80 nw_connection_set_state_on_nw_queue + 304
16 libnetwork.dylib 0x8c5a4 nw_connection_endpoint_report_on_nw_queue + 21732
17 libnetwork.dylib 0xb24a4 nw_endpoint_handler_report + 304
18 libnetwork.dylib 0x11509c -[NWConcrete_nw_endpoint_resolver startWithHandler:] + 2124
19 libnetwork.dylib 0x79d18 nw_endpoint_handler_path_change + 8984
20 libnetwork.dylib 0xa5798 nw_endpoint_handler_start + 1084
21 libnetwork.dylib 0xab124 __nw_connection_start_block_invoke + 1408
22 libnetwork.dylib 0xd5384 nw_connection_start + 252
23 CFNetwork 0x1b570 CFURLRequestCopyHTTPRequestMethod + 912
24 CFNetwork 0x1c1b0 CFHTTPMessageCopyBody + 536
25 CFNetwork 0x116be0 CFURLDownloadCancel + 77848
26 CFNetwork 0x19464 CFURLRequestSetURL + 10348
27 CFNetwork 0x12100 CFURLCacheSetMemoryCapacity + 8996
28 CFNetwork 0x110b8 CFURLCacheSetMemoryCapacity + 4828
29 CFNetwork 0x184e98 _CFNetworkErrorGetLocalizedDescription + 335348
30 CFNetwork 0x185034 _CFNetworkErrorGetLocalizedDescription + 335760
31 libdispatch.dylib 0x1e68 _dispatch_call_block_and_release + 32
32 libdispatch.dylib 0x3a2c _dispatch_client_callout + 20
33 libdispatch.dylib 0xb124 _dispatch_lane_serial_drain + 668
34 libdispatch.dylib 0xbcb4 _dispatch_lane_invoke + 444
35 libdispatch.dylib 0xcf80 _dispatch_workloop_invoke + 1784
36 libdispatch.dylib 0x16500 _dispatch_workloop_worker_thread + 648
37 libsystem_pthread.dylib 0x10bc _pthread_wqthread + 288
38 libsystem_pthread.dylib 0xe5c start_wqthread + 8
Post not yet marked as solved
We started noticing that for some users the app is crashing as soon as it opens. They cannot get past the issue unless the app is removed and re-installed. There are several similar, but related crashes that we are seeing and all pointing to CFNetwork. The main ones we are seeing are CFNetwork _CFURLStorageSessionCopyCache,
CFNetwork
_CFURLStorageSessionCopyIdentifier these are showing on our firebase crashlytics console.We recently updated some of the code within our app to use Async / Await and there are several API calls that are called on the app startup to get necessary data. The only test device we have with the issue has not used the app for some time before we updated and opened it. On this device, it crashes every time the app opens.On other devices, we do seem to get a crash after opening and closing the app repeatedly, which we think might be the same issue but are not 100% sure as we can't debug the issue when it occurs as it is very sporadic and never seems to occur on the simulator and only after reopening the app several times in a row.Configuration:
We have seen this occur on different versions of iOS. A few examples of devices are: the iPhone 6s running iOS 14.8.1 and iPhone 12 Pro running iOS iOS 15.3.1.Xcode version 13.3.1 (13E500a)Steps to Reproduce:
For the devices that crash every time, it seems the issue only happens on devices already logged in after updating to the latest version of our app v9.1.5 (306).For devices that don't crash on startup every time we have found that we need to open lots of apps in the background and then open and close our app and usually after about 5 times a crash occurs.
Post not yet marked as solved
Hey everyone, we've experienced strange behavior in the iOS system with a GHP profile and the PAC file evaluation when there's no internet connection.
The setup:
Router is not connected to the internet
Device connects to a Wi-Fi provided by the router
Device has mobile data disabled
Device has a proxy set via GHP with a PAC file URL
Device tries to access a website on a local IP address (e.g. 192.168.1.1)
PAC file:
function FindProxyForURL(url, host) {
if (shExpMatch(url, "*:993/*")){ return 'DIRECT';}if (shExpMatch(url, "*:465/*")){ return 'DIRECT';}if (shExpMatch(url, "*:587/*")){ return 'DIRECT';}
if (isPlainHostName(host) || shExpMatch(host, "*.local") ||
isInNet(dnsResolve(host), "10.0.0.0", "255.0.0.0") ||
isInNet(dnsResolve(host), "172.16.0.0", "255.240.0.0") ||
isInNet(dnsResolve(host), "192.168.0.0", "255.255.0.0") ||
isInNet(dnsResolve(host), "127.0.0.0", "255.255.255.0"))
return 'DIRECT';
return 'PROXY my.proxy.address;DIRECT';
}
The result:
The device is not able to connect to local addresses, the request times out.
Based on the PAC file rules, when accessing the 192.168.1.1 address, the proxy should have been bypassed and it should go directly:
isInNet(dnsResolve(host), "192.168.0.0", "255.255.0.0"). However, it seems, that the device is still trying to go via proxy which is unreachable since the router is not connected to the internet. The GHP profile has even the flag to bypass proxy if unreachable enabled:
<key>ProxyCaptiveLoginAllowed</key>
<true/>
<key>ProxyPACFallbackAllowed</key>
<true/>
If we remove the GHP profile from the device, everything works. And if the device has cellular data enabled, it works as well. This setup is used by a customer that is connecting to such router in elevators for some maintenance, so they usually have no signal there - the cellular interface is not working and from time to time, the webpage is successfully loaded - I assume that the device had a signal for a short period of time.
I just wanted to check with you if there's anything we do wrong in the proxy setup before reporting a bug. Right now we're trying to reproduce this behavior with CFNetworkDiagnostics and NetworkDiagnostics profiles installed so we have more logs. Although, we've noticed the following message in the logs:
CFNetworkAgent PAC Fetch failed with cached error [NSURLErrorDomain:-1009]
Have anyone experienced something similar? Thanks in advance!
Post not yet marked as solved
I want to reset the local network privacy. so I try the method mentioned here ( https://developer.apple.com/forums/thread/663839 ). but it doesn't work on my iPhone 13 mini running iOS 15.4.1.
anyone knows why?
Apple team I tried to implement the ssl pinning in iOS through info.plist using Pinned Domains Identity Pinning as found in the official apple blog: How to configure server certificates for your app https://developer.apple.com/news/?id=g9ejcf8y news.
As of now i have done the following changes something similar in info.plist :
And in code i have used simple URLSession as shown:
"https://wang.greenhub.example.org/sites/......./logo.png") else {
return
}
// URL session that doesn't cache.
let urlSession = URLSession(configuration: URLSessionConfiguration.ephemeral)
let task = urlSession.dataTask(with: imageUrl) { imageData, response, error in
DispatchQueue.main.async {
// Handle client errors
if let error = error {
self.HandleClientConnectionError(error: error)
return
}
// Handle server errors
guard let httpResponse = response as? HTTPURLResponse,
(200...299).contains(httpResponse.statusCode) else {
self.HandleServerError(response: response!)
return
}
self.AddImageToView(imageData: imageData!)
}
}
task.resume()
FYI we have api with multiple subdomains and thus according to the
NSIncludesSubdomains documentation here
says:
it doesn’t apply to the subdomains advanced.math.example.com or ancient.history.example.com because those subdomains have two additional path components.
Also it prohibits the use of wild cards so even if i tried to use *.example.org overall the SSL pinning does not seems to work in case of multiple subdomains scenario like mine even if i replace the SHA256-BASE64 pin with wrong ones.
Can anyone from apple suggest a solution for this or tell how can we use NSIncludesSubdomains find a solution for pinning against multiple subdomains
Post not yet marked as solved
As part of a security assessment, we discovered that our app is storing sensitive information in the cache.
After some research and considering the recommendations, we decide to use .ephemeral configurations for our URLSessions, so far so good.
However, taking a look at the content in the cfurl_cache_receiver_data table, we realized that some of those responses are not part of any of our endpoints, meaning that this is probably coming from requests made for third-party libraries that we use and we were able to confirm this by using a tool to inspect network traffic.
My understanding is the cache mechanism is attached to a URLSessionConfiguration and, at the same time, this configuration is tied to a URLSession. Since this is not our code and therefore different URLSessions it makes sense that this caches the responses for any request. Please correct me if this is wrong.
I am wondering if there is a way to disable the caching across the app (including requests made for third-party libraries?) or if there is a different/better approach to this?
I am attaching a screenshot of the cfurl_cache_receiver_data table content.
For example:
token=[value]. This is not the response of one of our endpoints, but an external one.
Thanks in advance!
PD: Is there a way to easily map the data in the cache.db with the particular endpoint/request?
Hi everyone,
i'm developing an app with Flutter and i've a problem with internet connectivity. Particularly, with the WIFI connection every work well, but when i turn off wifi and active the mobile connection 4G the app does not work and put out this errors:
Runner[1930:178958] Connection 1: encountered error(1:50)
Runner[1930:178953] Task <291B2B98-3FAE-47ED-BA1C-39F75580220C>.<1> HTTP load failed, 0/0 bytes (error code: -1009 [1:50])
Runner[1930:178960] Task <291B2B98-3FAE-47ED-BA1C-39F75580220C>.<1> finished with error [-1009] Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={_kCFStreamErrorCodeKey=50, NSUnderlyingError=0x282f9c210 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_NSURLErrorNWPathKey=unsatisfied (Denied over cellular interface), interface: pdp_ip0, ipv4, dns, expensive, _kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <291B2B98-3FAE-47ED-BA1C-39F75580220C>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <291B2B98-3FAE-47ED-BA1C-39F75580220C>.<1>"
), NSLocalizedDescription=The Internet connection appears to be offline., NSErrorFailingURLStringKey=https://graph.facebook.com/v13.0, NSErrorFailingURLKey=https://graph.facebook.com/v13.0, _kCFStreamErrorDomainKey=1}
How to fix it?
Forgive me if I have not used the forum to its fullest, but I am a new user. :)
Thanks in advance to those who will help me!
Post not yet marked as solved
The parameters of the completion handler are (data: Optional<Data>, urlResponse: Optional<Data>, error: Optional<Error>). Here is an exhaustive switch statement of the parameter combinations:
switch (data, ulrResponse, error) {
case (.some, .some, .some):
case (.some, .some, .none):
case (.some, .none, .some):
case (.some, .none, .none):
case (.none, .some, .some):
case (.none, .none, .some):
case (.none, .some, .none):
case (.none, .none, .none):
}
Which combinations of values may be provided and which will not?
For example, I think it's fair to say that both (.some, .none, .some) and (.some, .none, .none) are invalid because a response would have to be provided in order to receive data to pass to the closure, and the documentation states:
If a response from the server is received, regardless of whether the request completes successfully or fails, the response parameter contains that information.
Post not yet marked as solved
My app is working fine on all devices except on one specific device iPhone 12 Pro Max, that give error "502 Bad Gateway".
App is unable to connect to server, what could be the reason for this, is this related to firewall or VPN?
This happens only on a single device of the client but on our local testing devices it works perfectly fine.
Please do share your thoughts as this issue seems rather unexpected where the app on all other devices is working fine except for one.
Thank. you
Post not yet marked as solved
I'm trying to create a network request mocking infrastructure for my iOS app. I'm using a mock URLProtocol to do this. My challenge is that I want to load custom data for each URLSession. In my setupWithError() in my unit tests, I basically do:
let config = URLSessionConfiguration.ephemeral
config.protocolClasses = [URLProtocolMock.self]
let session = URLSession(configuration: config)
APIManager.shared.session = session
<session.URLProtocolMock>.loadJSMocks(filename: "AddItemUITest.js")
All of the examples I see for doing mocks this way, create static variables in the URLProtocolMock to allow configuring data. I'd like to be able to run tests in parallel, so static variables won't work.
I couldn't find an obvious way to get the protocol instance from the URLSession. Is there a non-obvious way? ;-)
Thanks!
Greg
P.S. And in the course of writing this, I realized that I have another problem with static APIManager session sharing. But that one I know how to solve :-)