2016-09-29 26 views
6

Bir yükleme işleminin bant genişliğini, örn. Alamofire?

Kullanıcı uygulamayı kullanırken ve daha önemli şeyleri indirme ve indirme yaparken arka plana veri yüklemek istiyorum.
Bu nedenle, belirli koşullar altında arka planda bant genişliğini kısmak istiyorum.iOS: gaz bant genişliği örn. Alamofire

Şu ana kadar bulduğum tek olası maxBandwidthPerSecond özelliğine sahip ASIHTTPRequest kullanıyor, ancak bu kitaplık çok eski, daha yeni bir şey kullanmak istiyorum.

+0

İlgili? [İnternet bağlantısını yavaşlatmak için IPFW'den alternatif bir çözüm arıyor] (http://stackoverflow.com/q/33064329/2415822) – JAL

cevap

0

Chilkat API olasılık, bu gibi kullanılabilir bant genişliği kısma sağlayan bir CKOSocket() içerir:

// To use bandwidth throttling, the connection should be made using the socket API. 
// This provides numerous properties to customize the connection, such as 
// BandwidthThrottleDown, BandwidthThrottleUp, ClientIpAddress, ClintPort, Http Proxy, 
// KeepAlive, PreferIpv6, RequireSslCertVerify, SoRcvBuf, SoSndBuf, SoReuseAddr, 
// SOCKS proxy, TcpNoSDelay, TlsPinSet, TlsCipherSuite, SslAllowedCiphers, etc. 

let socket = CkoSocket() 
var maxWaitMs: Int = 5000 
var success: Bool = socket.Connect("content.dropboxapi.com", port: 443, ssl: true, maxWaitMs: maxWaitMs) 
if success != true { 
    print("\(socket.LastErrorText)") 
    print("Connect Fail Reason: \(socket.ConnectFailReason.integerValue)") 
    return 
} 

// Set the upload bandwidth throttle rate to 50000 bytes per second. 
socket.BandwidthThrottleUp = 50000 

Check this Diğer dokümanlar için.

Dokümantasyondaki örnek, REST API ile yükleme bant genişliği daraltmanın nasıl kullanılacağını gösterir. Bir dosya akışı kullanarak, aktarım için kullanılabilecek bant genişliğindeki bir limiti kullanarak bir dosyayı Drobox'a yükler.

0

Ben Alamofire (swift parçası) hakkında bir şey bulamıyorum ama AFNetworkkullanabilirsiniz.

sen görebileceğiniz gibi bu link (AFNetworking/AFNetworking/AFURLRequestSerialization.h) kaynakları raporunu:

/** 
Throttles request bandwidth by limiting the packet size and adding a delay for each chunk read from the upload stream. 
When uploading over a 3G or EDGE connection, requests may fail with "request body stream exhausted". Setting a maximum packet size and delay according to the recommended values (`kAFUploadStream3GSuggestedPacketSize` and `kAFUploadStream3GSuggestedDelay`) lowers the risk of the input stream exceeding its allocated bandwidth. Unfortunately, there is no definite way to distinguish between a 3G, EDGE, or LTE connection over `NSURLConnection`. As such, it is not recommended that you throttle bandwidth based solely on network reachability. Instead, you should consider checking for the "request body stream exhausted" in a failure block, and then retrying the request with throttled bandwidth. 
@param numberOfBytes Maximum packet size, in number of bytes. The default packet size for an input stream is 16kb. 
@param delay Duration of delay each time a packet is read. By default, no delay is set. 
*/ 
- (void)throttleBandwidthWithPacketSize:(NSUInteger)numberOfBytes 
            delay:(NSTimeInterval)delay; 

@end 

Bir senin özel "NetworkManagerın" objektif-C sınıfı inşa edebileceğini ve Hızlı projenize kolayca aktarın.

İlgili konular