user2353899
user2353899

Reputation:

Cancel Upload files on Google Drive IOS SDK

I'm working on IOS APP that use google drive to manipulate files , so i'm reading and downloading , uploading file every thing works good but i cant find how to cancel uploading files because some times user need to cancel a download or an upload but ther are no documentation about this . thanks

Upvotes: 1

Views: 943

Answers (1)

user2353899
user2353899

Reputation:

I found How to cancel the Upload just do [ticket cancelTicket]; but how i can access to this ticket from another method , her is my upload method

- (void)insertFileWithService:(GTLServiceDrive *)service
                    title:(NSString *)title
              description:(NSString *)description
                 parentId:(NSString *)parentId
                 mimeType:(NSString *)mimeType
                     data:(NSData *)data
                fileIndex:(NSIndexPath *)fileIndex
          completionBlock:(void (^)(GTLDriveFile *, NSError *))completionBlock{
GTLDriveFile *file = [GTLDriveFile object];

file.title = title;
file.descriptionProperty = description;
file.mimeType = mimeType;

if (parentId != nil) {
    GTLDriveParentReference *parentRef = [GTLDriveParentReference object];
    parentRef.identifier = parentId; // identifier property of the folder
    file.parents = @[ parentRef ];
    //file.parents = [NSArray arrayWithObjects: parentId, nil];
}

GTLUploadParameters *uploadParameters =
[GTLUploadParameters uploadParametersWithData:data MIMEType:mimeType];
GTLQueryDrive *query =
[GTLQueryDrive queryForFilesInsertWithObject:file
                            uploadParameters:uploadParameters];

GTLServiceTicket *queryTicket =
[service executeQuery:query
    completionHandler:^(GTLServiceTicket *ticket,
                        GTLDriveFile *insertedFile, NSError *error) {


        if (error == nil) {
            completionBlock(insertedFile, nil);

        } else {
            //NSLog(@"An error occurred: %@", error);
            completionBlock(nil, error);
        }
    }];

queryTicket.uploadProgressBlock = ^(GTLServiceTicket *ticket,
                               unsigned long long numberOfBytesRead,
                               unsigned long long dataLength) {
   float myprogress = (1.0 / dataLength * numberOfBytesRead);

   NSLog(@"progress %@ => %f",title,myprogress);
   self.fileManagementViewController.fileTransferProgressTableViewController.progress = myprogress;

};
}

thanks

Upvotes: 2

Related Questions