How to cancel a video upload in progress using the Facebook iOS SDK?

旧城冷巷雨未停 提交于 2019-12-08 05:48:52

问题


I'm using the Facebook iOS SDK to post videos from my app to the user's facebook.

I'm trying to allow the user to cancel the upload after the upload has started.

These are the methods that starts the upload:

- (void)startUpload
{   
    NSArray* permissions = [[NSArray alloc] initWithObjects:
                            @"publish_stream", nil];
    [facebook authorize:permissions];
    [permissions release];
}

- (void)fbDidLogin
{
    NSString *filePath = [videoNSURL path];

    NSData *videoData = [NSData dataWithContentsOfFile:filePath];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   videoData, @"video.mov",
                                   @"video/quicktime", @"contentType",
                                   videoTitle, @"title",
                                   videoDescription, @"description",
                                   nil];
    [facebook requestWithGraphPath:@"me/videos"
                         andParams:params
                     andHttpMethod:@"POST"
                       andDelegate:self];
}

I cannot find any methods inside Facebook.h that comes with the Facebook iOS SDK that allows me to cancel the upload.

Even if I do a [facebook release], it will still not cancel the FBSession which is trying to upload the video. Which means I'll get a exc_bad_access when the upload is complete when FBSession tries to inform the facebook object that the upload is complete.


回答1:


I added the following methods:

FBRequest

(void) cancel {
   [_connection cancel];
   [_connection release], _connection = nil;
}

Facebook

(void)cancelPendingRequest {
  [_request cancel];
  [_request release], _request = nil;
}

cancelPendingRequest will allow me to cancel a video upload in progress.



来源:https://stackoverflow.com/questions/8080581/how-to-cancel-a-video-upload-in-progress-using-the-facebook-ios-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!