3

I want to control how many bits are transferred per second. Is it possible to do this? For example, can I set a rate somewhere so that my files get downloaded at 2 kbps?

I've looked through the documentation and there doesn't seem to be anything, but maybe I'm missing something.

Edit: I'm performing an upload/download in the background of an extension, as described here: https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW1

arcticmatt
  • 1,956
  • 1
  • 19
  • 36
  • 1
    Can you elaborate? All the examples I've seen for performing uploads/downloads in extensions (see my edit) use NSURLSession. – arcticmatt Aug 11 '14 at 23:22
  • `NSURLConnection` is certainly what we'd have used under iOS 6 or earlier; I don't see how it's advantageous over the newer `NSURLSession` — even for this particular niche application — under iOS 7+. – Tommy Aug 11 '14 at 23:33
  • Woops, I deleted my comment! I said that you should use `NSURLConnection` or something like that. Reason I say that is, I read that `NSURLConnection` would support bandwidth throttling. But, I am reading up now and that's just simply not true. Neither is the case for `NSURLSession` – taylorcressy Aug 11 '14 at 23:36
  • Curious, why would you want to limit the transfer rate? Is this intended for the user or just so you can test having a slow connection? – Acey Aug 11 '14 at 23:51
  • Throttling is something you'd do server side, not client side. – TheCodingArt Aug 12 '14 at 00:03
  • I want to limit the transfer rate so I can have a guaranteed transfer time. With this, I can time my transfer time so that the background task completes after my extension stops running. When this happens, the system will launch my containing app in the background and call the application:handleEventsForBackgroundURLSession:completionHandler: app delegate method. So basically, I want to throttle it so that I can communicate with my containing app from my share extension. Seems like the throttling can't really be done though. Thanks for the help guys. – arcticmatt Aug 12 '14 at 00:32
  • 2
    Are you throttling for diagnostic purposes? For that you'd just use network link conditioner. – Rob Aug 12 '14 at 00:51
  • Network link conditioner...awesome! Thanks Rob. – arcticmatt Aug 12 '14 at 02:21

2 Answers2

1

Have you tried using timers ask for your data in chunks?

Keep a counter of the total amount of data downloaded and the total time. Control the rate by sleeping until you've satisfied your data rate requirement.

BenF
  • 11
  • 2
1

The Network Link Conditioner is designed to allow you to throttle the connection speed for diagnostic purposes. A Mac rendition (which is used for testing iOS simulator apps as well as Mac OS X apps) is available as part of the Hardware IO Tools (choose "More Developer Tools..." on the "Open Developer Tools" submenu of the "Xcode" menu. It's part of the "Hardware IO Tools" that you'll see on the web page that pops up.

Also, in iOS, when a device has been configured for developer use, in the "Developer" section of the "Settings.app", you'll see an iOS rendition of the Network Link Conditioner, too.

There are many references to the Network Link Conditioner online, but see NSHipster's discussion.

Rob
  • 415,655
  • 72
  • 787
  • 1,044