ios - SLRequest 进度回调(iOS 6)

标签 ios facebook upload progress

我正在使用适用于 iOS 6 的新社交 API 实现 Facebook 视频上传,一切正常,只是我没有找到一种方法来了解上传的进度……Apple 似乎唯一的 API提供的是,如果上传完成或者失败,有可能他们是如此--------他们没有提供知道它的方法?

我也没有发现任何关于这个主题的问题,我不可能是唯一对此感兴趣的人,如果有人知道其他任何事情,请告诉我们。

最佳答案

我一直在努力解决这个问题,终于让它工作了。我想我会分享我的片段:

-(void)sendTwitter {
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:
                              ACAccountTypeIdentifierTwitter];

[account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
    if (granted == YES) {
        NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
        if ([arrayOfAccounts count] > 0) {
            twitterAccount = [arrayOfAccounts lastObject];

            NSString *status = @"Secrets";
            UIImageView *uploadImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 640, 480)];
            UIImage *uploadImage = [image resizedImageToFitInSize:uploadImageView.bounds.size scaleIfSmaller:NO];

            NSURL *requestURL = [NSURL URLWithString:@"https://upload.twitter.com/1.1/statuses/update_with_media.json"];

            SLRequest *postRequest = [SLRequest
                                      requestForServiceType:SLServiceTypeTwitter
                                      requestMethod:SLRequestMethodPOST
                                      URL:requestURL parameters:nil];
            [postRequest addMultipartData:UIImageJPEGRepresentation(uploadImage, 0.6) withName:@"media[]" type:@"multipart/form-data" filename:nil];
            [postRequest addMultipartData:[status dataUsingEncoding:NSUTF8StringEncoding] withName:@"status" type:@"multipart/form-data" filename:nil];
            [postRequest setAccount:twitterAccount];

            NSURLRequest *preparedRequest = [postRequest preparedURLRequest];

            AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:preparedRequest];

            [operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
                NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
            }];
            [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
                    NSLog(@"Twitter upload success");
                    [self completedSendingPhotos];
                } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                    NSLog(@"Twitter upload error");
                }];

            [operation start];
        }
    }
}];

关于ios - SLRequest 进度回调(iOS 6),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13875236/

相关文章:

ios - Swift:初始化自定义 UITableViewCell 时获取 UITableView 框架

ios - Ionic pro - 构建并发布到 Apple Store

ios - Unity FB.API 请求在 iOS 上返回不支持的 URL,在编辑器中工作

file - 表单数据 : wrong Content-Type for . p7m 文件

javascript - CKEditor - 将图像拖放到带标题的图像中

Facebook - 如何通过 URL 上传照片?

ios - 在 Xcode 8.3 上向 iOS 10 添加角标(Badge)图标

ios - 为什么主事件框架宽度大于高度,即使它处于纵向模式?

python - 如何通过 django-scoial-auth 中的 django 应用程序获取详细信息和 Facebook 相册

facebook - 确定用户何时创建 Facebook 帐户