How do we find transfer rate in swift

I wanted to know the transfer rate (network speed) in my swift application. There is one thread runs in the background to monitor the transfer reate. If the transfer rate is below the certain limit, it will do some process. I haven't seen any iOS API to directly provide the transfer rate. How do we do this in iOS

Replies

I haven't seen any iOS API to directly provide the transfer rate.

Neither have I.


rate = (amount transferred) / (time)


You may need to calculate it by yourself.

ok. In this case we transfer some data to server and find the rate. Is there any sample code that can post here ?

Sorry, cuurently I have no code ready for showing here. And many things depend on how your transfer is made.

Just need to get Date() at beginning of transfer, Date() at the end of transfer, make the difference.

But take care of precision.

Network framework added comprehensive support for collecting connection metrics in iOS 13. See Collecting Network Connection Metrics and the associated WWDC session.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"