2014-03-07 54 views
1

我正在嘗試SPDY for iOS應用程序,它目前使用AFNetworking(2.1.0)來處理HTTP請求。服務器端,我使用的是Google App Engine(與SPDYCheck一起檢測),它對SPDY友好。SPDY for iOS with AFNetworking

下面是我如何在我的代碼中集成SPDY。

我使用AFHTTPRequestOperationManager

@interface MyClient : AFHTTPRequestOperationManager 

我嵌入式SPDY在initWithBaseURL:

- (id)initWithBaseURL:(NSURL *)url { 
    self = [super initWithBaseURL:url]; 
    if (!self) { 
     return nil; 
    } 

    // SPDY Config 
    NSString *spdyURL = [NSString stringWithFormat:@"%@://%@:443",url.scheme, url.host]; 

    [SPDYURLConnectionProtocol registerOrigin:spdyURL]; 
    ... 
    } 

注意我的網址與格式https://myapp.appspot.com/_ah/所以我傳遞給SPDY registerOrigin:時spdyURL看起來像重新格式化https://myapp.appspot.com:443

我想這就是我需要的一切?但添加SPDY代碼後,我無法發送請求。調試消息顯示以下錯誤:

error response from api/users/v1/is_token_valid : 
Error Domain=NSURLErrorDomain 
Code=-1001 
"The request timed out." 
UserInfo=0xdc2c250 {NSErrorFailingURLStringKey=https://myapp.appspot.com/_ah/api/users/v1/is_token_valid? 
user_token=[a_token], 
NSErrorFailingURLKey=https://myapp.appspot.com/_ah/api/users/v1/is_token_valid? 
user_token=[a_token], 
NSLocalizedDescription=The request timed out., NSUnderlyingError=0xf270e60 "The request timed out."} 

我根本沒有線索。希望在iOS上有SPDY經驗的人可以幫忙!

回答

2

不幸的是,Apple的TLS實現不支持Google App Engine使用的NPN。您可以在CocoaSPDY GitHub README中閱讀更多內容。

目前,您不能在Google App Engine中使用CocoaSPDY。

+0

是的,我在github上發佈了一個問題,並得到了相同的回覆.. – xialin

+0

@David Caunt你好先生我可以整合CocoaSPDY的Mozilla FireFox ios應用程序? – ShreePool

3

確實,Apple在默認的TLS實現中不支持NPN。但是有一些SPDY庫使用OpenSSL(它支持NPN)。

這是一個他們: https://github.com/locationlabs/SPDY-for-iPhone

+0

你以前是否嘗試過。我確實找到了回購,但不確定它是否可靠。 – xialin

+0

我試圖運行它,它工作,但沒有在任何項目中使用它。 – kam800

0

它是確定的嗎? 我看到SPDY協議支持現在在OS X Yosemite和iOS 8的NSURLSession中可用,並且由NSURLSession透明地支持。 查看詳情:https://developer.apple.com/videos/wwdc/2014/ [基礎網絡新增功能] 但是爲什麼它不起作用? 當我使用CocoaSPDY,設置manager.session.configuration.protocolClasses = @ [[SPDYURLSessionProtocol類]];沒關係;