グラフに投稿しているだけなので、動画のアップロードに固有のものではないと思いますが、次のコードを使用すると、アップロードが停止することがあります。小さいビデオ(<20MB)はある程度確実に通過しますが、大きいビデオ(50〜200 MB)は失敗することが保証されています。
NSData *videoData = [NSData dataWithContentsOfFile:video.localURL options:NSDataReadingMappedAlways error:&error];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, video.localURL,
@"video/quicktime", @"contentType",
video.name, @"title",
NSLocalizedString(@"Test http://www.apple.com", @"Facebook upload description"), @"description",
nil];
FBRequest *request = [FBRequest requestWithGraphPath:@"me/videos" parameters:params HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(@"result: %@, error: %@", result, error);
[[NSNotificationCenter defaultCenter] postNotificationName:FacbookUploadFinishedNotification object:nil];
}];
アップロードの進行状況に関する通知を受け取るために、FBURLConnectionにパッチを適用しました。
- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite {
NSDictionary *userInfo = [NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:
[NSNumber numberWithInt:totalBytesWritten],
[NSNumber numberWithInt:totalBytesExpectedToWrite],
nil]
forKeys:
[NSArray arrayWithObjects:
@"bytes",
@"totalBytes",
nil]
];
[[NSNotificationCenter defaultCenter] postNotificationName:FacebookUploadProgressNotification
object:self
userInfo:userInfo];
}
私には、Facebookサーバーが応答を停止しているように見えます…didSendBodyDataが呼び出されなくなり、しばらくするとリクエストがタイムアウトします。
FBアプリで同じ動画をアップロードすると機能します…</p>
編集:ああ、このアプリで使用しているFacebookアプリIDがまだ送信されていないことを追加するのを忘れました。リクエストはおそらくいくつかの(信頼性の低い)テストサーバーに送られますか?アップロードされた動画は私のタイムラインに表示されますが…</p>