267 questions
-1
votes
2
answers
101
views
Meaning of Error and httpStatus.statusCode returned from Swift request using URLSession.shared.dataTask
I am doing a POST request using URLSession.shared.dataTask which returns data, response and error. I would think that Error would be the same as a failed request. However, I can get the request to ...
0
votes
1
answer
69
views
Is it true that there is no way at all to subclass URLSessionDataTask, and if so is there a way to add an associated property?
I've always wanted to do something like
class URLSessionDataTask_Plus: URLSessionDataTask {
var obs: NSKeyValueObservation? = nil
// store the progress observer there
}
which would be ...
-1
votes
1
answer
491
views
Swift: try await URLSession.shared.data(from: url) exits without throwing and without result if endpoint is down
I have a .NET core WebApi endpoint with a PING method that simply returns "PONG" when called.
In a SwiftUI app (XCode 15 with iOS 17.2 target) I use this code for calling it:
func ping () ...
0
votes
0
answers
47
views
URLSessionDataTaskPublisher not handled errors properly
I have iOS application which use remote API for receiving some data (transactons) by periods.
API allows make one call per 10 seconds (otherwise my IP will be blocked). Because of network issues, ...
0
votes
0
answers
44
views
URL Session Data Structure
I am building iOS app where I insert an input string and search this string using Google , then I get the data string back and use it to search for specific word or series of characters
I use ...
-1
votes
1
answer
126
views
dataTask() in a loop: Waiting and breaking
My app downloads a couple of files from a server, using a URLSessionDataTask. When a downloads finishes successfully (and without any errors), then it should start the next download. If there is any ...
1
vote
1
answer
684
views
Ambiguous use of 'dataTask(with:completionHandler:)'
I updated the Xcode to 14.3 and when I tried to run a project, I am getting this error:
"Ambiguous use of 'dataTask(with:completionHandler:)'"
Do you know how I can fix this issue ?
...
1
vote
1
answer
805
views
Swift async cancel like URLSession
when i use callback function with URLSession, i can use URLSessionDataTask to cancel a task
let task = URLSession.shared.dataTask(with: URLRequest(url: URL(string: "")!)) { data, response, ...
0
votes
0
answers
34
views
How do I reduce lag when loading image with URLSession?
There is a lag in loading the UIImageView called profilePic. How can I get rid of this lag?
The problem seems to be in my addImage() method.
private func addImage() {
let donorId = ...
2
votes
1
answer
3k
views
Cannot convert return expression of type 'AnyPublisher<T, any Error> in Combine
I am new to combine . I created an generic function which return AnyPublisher with result (T) and Error(Service error) it the custom error message . I have the pass the urlSession with ...
-1
votes
2
answers
863
views
Headers not being set correctly, Swift API Call [closed]
Trying to do an API call, and have used a data task before. Now I tried the DataPublisher instead with combine. I have developed an API that needs authorisation with a specific token. Sadly the auth ...
1
vote
1
answer
969
views
How to print the api response to the console? Xcode 14
I am learning about API's and decided to practice using them by writing a simple function to call an api and print the response. The issues I am having is that the response is not printing to the ...
0
votes
1
answer
1k
views
URLSessionDataTask - upload parameters with multipart/form-data content type
I would like to create body like in this curl example:
curl --location --request POST 'https://request.url' \
--header 'Authorization: Bearer xxx' \
--form 'name="Name"' \
--form 'data="...
0
votes
1
answer
98
views
URLSession.shared struct property isn't working for Combine API call
I have following APILoader struct in my network layer.
struct APILoader<T: APIHandler> {
var apiHandler: T
var urlSession: URLSession
init(apiHandler: T, urlSession: ...
0
votes
0
answers
144
views
Make a Get Request api to a JWT enabled endpoint
I am trying to make a get request to a JWT enabled API but I am getting my result in bytes instead of objects
after the user logs in it is expected to go the next page where it lists user projects, at ...
0
votes
0
answers
549
views
Why is this URLSession.datatask not working in Swift 5 for macos
I am trying to make my own DynamicIP updater as a command line tool so I can set it up to run as a launch agent. I thought this would be a pretty simple thing to do, but I am not getting anything ...
1
vote
0
answers
161
views
Need clarification between URLError. dataNotAllowed and URLError.notConnectedToInternet
I tried to handle URLSession dataTask error. When dataTask is started without internet connection , i'm getting URLError.dataNotAllowed error. When will I get URLError.notConnectedToInternet ?
0
votes
0
answers
898
views
How to check if one of URLSession tasks returned an error and if so to stop code execution?
I need to make 2 API calls simultaneously. I have 2 URLs for the calls, and if one of the calls will return any error I want to stop all the code execution.
How I tried to do it:
I have a function ...
0
votes
0
answers
1k
views
How to properly cancel and restart an URLSessionDataTask Swift
This is my request funtion:
func receiptValidation(completion: @escaping(_ isPurchaseSchemeActive: Bool, _ error: Error?) -> ()) {
let receiptFileURL = Bundle.main.appStoreReceiptURL
guard ...
1
vote
1
answer
771
views
Getting nil data when try to cancel a task and restart it again Swift
What I am trying to do:
Sometimes my URLSession call request takes a too long time to give a response back. That's why I am trying to call the call request again if it doesn't give a response back ...
2
votes
1
answer
927
views
Do I need place urlsession datatask on another DispatchQueue or it's done automatically?
Didn't have any experience with datatasks and urlsessions before. So I'm curious. Case is - trying to have a table with infinite scroll. When this method called
tableView(_ tableView: UITableView, ...
4
votes
1
answer
999
views
Swift Combine in UIKit. URLSession dataTaskPublisher NSURLErrorDomain -1 for some users
After switching our API Client to Combine we start to receive reports from our users about error "The operation couldn’t be completed (NSURLErrorDomain -1.)" which is the error....
0
votes
1
answer
318
views
How to parse html that has the updated DOM? Swift
I am fairly knew to coding and am parsing html data from a webiste. The problem is that the elements that I can manually inspect when I view the website are very different from the source code. I ...
1
vote
2
answers
552
views
url data task is not showing the right content when parsed with SwiftSoup? Swift 5
I am pretty new to swift and have an app that performs a simple url data task to parse the html contents of that website. I was trying to load certain elements but wasn't getting the content that I ...
0
votes
1
answer
104
views
Translate data task function for background upgrade from Swift to Objective C
I'm trying to implement a function in AppDelegate.m in order to update my app in background.
I've found an article online (this is the link: https://medium.com/@vialyx/ios-dev-course-background-modes-...
0
votes
2
answers
429
views
URLSession dataTask execution order
i am trying to fetch images data using URLSession dataTask the urls are fetched from a firebase firestore document that contains each download path using for loop in snapShotDocuments in ascending ...
0
votes
1
answer
202
views
datatask not executed, request is null
import Foundation
let headers = [
"x-rapidapi-key": "myKey",
"x-rapidapi-host": "movie-database-imdb-alternative.p.rapidapi.com"
]
let urlR = URL(...
-2
votes
1
answer
476
views
A question about URLSessionDataTask and Combine in Swift
In an article, I saw a code snippet like below:
extension URLSessionDataTask: Cancellable {}
extension URLSession: NetworkService {
public func fetchData(with request: URLRequest, handler: @...
1
vote
1
answer
1k
views
URLSession dataTask long delay
When I'm requesting API from my code I got response after 4-6sec which is way too long. From Postman I'm getting response after 120ms. Is that something in my code goes wrong?
here is my code, I'm ...
0
votes
1
answer
188
views
How to make serial queue for a few URLSession.DataTaskPublisher?
I have several datataskpublisher, which performs requests to the server, from different application screens. How to make them run serial?
Below will be a rough example
This is a service that performs ...
8
votes
1
answer
6k
views
In Swift, how do you get the error type from UrlSession
I have the following code in my network logic:
let task = urlSession.dataTask(with: request) { [weak self] (data, response, error) in
if let error = error {
if error....
1
vote
1
answer
82
views
Asynchronous thread in Swift - How to handle?
I am trying to recover a data set from a URL (after parsing a JSON through the parseJSON function which works correctly - I'm not attaching it in the snippet below).
The outcome returns nil - I ...
1
vote
0
answers
401
views
Track the progress of more than one data tasks at the same time in swift
I am downloading a couple of images and want to show the user some kind of progress until its finished. I found a way to track the progress of data tasks from this question get progress from ...
0
votes
0
answers
272
views
Process a dataTask GET request on background
I have an API to get about 1000 records from a GET request. Currently I'm using dataTask to get the content via URLSession. Complication is the request just freeze as soon as it enters to the ...
1
vote
0
answers
81
views
Do you need to use URLSession's dataTask(with: URL) inside of an Operation class's main() method?
Do you need to use URLSession's dataTask(with: URL) inside of an Operation class's main() method?
For example:
class Downloader: Operation {
let postDetailsPage: PostDetailsPage
init(_ ...
2
votes
2
answers
3k
views
Should I choose URLSessionDataTask or URLSessionDownloadTask for getting image
I use URLSession and URLSessionDataTask to get an image from server and display it in an app. I had a look here. It looks like URLSessionDownloadTask has more options.
Currently I use the following ...
0
votes
0
answers
64
views
How to control the concurrent download counts in iOS?
I have an array of video URLs that need to be downloaded. To keep the overall performance, I want to limit the concurrent download counts to 2. For example, I want to start the first two download ...
1
vote
3
answers
532
views
JSON networking request not entering URLSession.shared.dataTask
I am having problems finding out why my dataTask returns an empty result.
While going through My NetworkingManager class it appeared that it never enters the URLSession.shared.dataTask. Does anyone ...
0
votes
1
answer
157
views
Attach parameters to NSURLSession Delegate Method
I would like to pass a parameter into my delegate to determine to continue or check for cert.
- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge ...
0
votes
0
answers
52
views
Why isn't the dataTask's completion handler being called?
I have this nagging problem that I just can't seem to fix. I'm trying to call a function within a particular class (called BMUserManagementService), but for some reason the completion handler in the ...
0
votes
1
answer
248
views
URLSession omits delegate's redirection management method
I am sending a DataTask to some website and in URL I have redirection to localhost (https://...&redirect_uri=http://localhost...). Overall in that call I am getting about 5 redirections, where ...
1
vote
0
answers
724
views
how to handle URLSession.shared.dataTask properly
Hi developers im having some issue or misplaced tasks
so i had to develop a framework with some functions
this is my main FUNCTION where the issue began
func saveDataDevice(idPos: String, ...
3
votes
1
answer
1k
views
SSL Error occurs in URL Session data task call back in certain devices only
For some users our app is throwing NSError while trying to call a secured server API using URLSession data task. Below is the detail of the error:
error-domain: NSURLErrorDomain
nserror-code: -1202
...
1
vote
0
answers
297
views
How to fix the Background download problem in IOS over cellular data
I have a ebook related app live on app store. This app downloads big files (ranging from ~100MB - 1GB) in background mode. Out of 100 users 10 users have reported problems with the download when they ...
0
votes
0
answers
117
views
URLSession's dataTaskPublisher ends with a 'Cancelled' response vs regular completion. Why? [duplicate]
Environment:
Xcode Version 11.3 (11C29)
Apple Swift version 5.1.3
Scenario:
Combine Neophyte attempting to learn URLSession.shared.dataTaskPublisher
Details:
I made a simple app to access weather ...
2
votes
1
answer
435
views
NSURLSessionDataTask does not work on macOS, "A server with the specified hostname could not be found."
Why does dataTaskWithURL work on iOS, but not on macOS?
The error message is:
Client-Error: A server with the specified hostname could not be found.
My routine is as follows:
- (void)loadHTML {
...
-1
votes
1
answer
581
views
the code is not entering the completion handler of the data task
The completion handler code is not getting executed. while i debug the code its coming till the session.datatask and after that its not getting into the completion handler. we are actually migrating ...
3
votes
4
answers
5k
views
How to make URLSession to work when app is moved to background
On a button click, I have to implement multiple API calls to get the data and write that data to file. I am using Operation Queue and URLSession datatask to implement this. While this API calls are in ...
1
vote
2
answers
2k
views
Is there a way to force ios system clear some (or all) app's cache?
My app downloading and saving some support data to 'Library/Caches' directory. According to documentation,
Use this directory to write any app-specific support files that your app can re-create ...
1
vote
1
answer
2k
views
Xamarin: NSMutableUrlRequest and NSUrlRequest with POST method and headers and data?
I have a Xamarin project where I am able to make GET calls without headers to something like "reqres.in" API like:
public Task<string> GetData()
{
TaskCompletionSource<string> tcs = ...