Bolts framework continueWithBlock error

1.6k views Asked by At

I've been working AWS s3 for a while now and had little problems until lately. I import the framework through cocoapods. Recently, I reinstalled cocoapods in light of this post.

Afterwards, I had a million and one "use of undeclared type: errors, most in primitive types. I ultimately resolved this (for the most part) by uninstalling cocoapods, reinstalling cocoapods, deleting, cleaning, then reinstalling pods for my specific project (with a bunch of project cleans as well).

I had an issue where Bolts was not included (even though I believe it's part of AWSCore). I added pod Bolts into my Podfile and added #import <Bolts/Bolts.h> into my obj-C -> Swift bridge file.

Now, Bolts was recognized, but I am getting an error "Cannot invoke 'continueWithBlock'" with an argument list of type '((BFTask!) -> _)' error with the following code:

transfer_manager.getObject(request).continueWithBlock(//error here
                    {(task: BFTask!) in
                           //completion logic
                            return nil //was not necessary prior
                    })

bridge.h:

#import <Bolts/Bolts.h> //was unneeded before reinstalling cocoapods
#import <AWSCore/AWSCore.h>
#import <AWSS3/AWSS3.h>
#import <AWSDynamoDB/AWSDynamoDB.h>
#import <AWSSQS/AWSSQS.h>
#import <AWSSNS/AWSSNS.h>
#import <AWSCognito/AWSCognito.h>

finally, my Podfile:

platform :ios, '8.0'enter code here

source 'https://github.com/CocoaPods/Specs.git'
pod 'Bolts' #was unneeded before reinstalling cocoapods
pod 'AWSCore'
pod 'AWSAutoScaling'
pod 'AWSCloudWatch'
pod 'AWSDynamoDB'
pod 'AWSEC2'
pod 'AWSElasticLoadBalancing'
pod 'AWSKinesis'
pod 'AWSLambda'
pod 'AWSMachineLearning'
pod 'AWSMobileAnalytics'
pod 'AWSS3'
pod 'AWSSES'
pod 'AWSSimpleDB'
pod 'AWSSNS'
pod 'AWSSQS'
pod 'AWSCognito'

Any ideas on how to (as I see the problem) get Xcode / Swift to recognize Bolts/BFTask properly again?

3

There are 3 answers

0
Ryan On BEST ANSWER

You can use AWSTask! in replacement of BFTask! (it is a subclass) to silence xcode.

1
jbcaveman On

I resolved this exact head-banging issue after trying the same steps as you by reverting my Pods to my last stable configuration.

pod 'Bolts', '1.1.5' 
pod 'AWSCore', '2.1.1'
pod 'AWSS3', '2.1.1'

Sucks to have to do that, but hopefully it's a temporary workaround. My app is building & functioning fine now. Hope this help you, too.

0
Saumil Shah On

Just replace the word of BFTask to AWSTask.

Import following file & framework

#import <AssetsLibrary/AssetsLibrary.h>
#import "AWSS3.h"
#import "Constants.h"

Give File path here

   - (void)fileUpload {
                NSError *error = nil;
                if (![[NSFileManager defaultManager] createDirectoryAtPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"upload"]
                                               withIntermediateDirectories:YES
                                                                attributes:nil
                                                                     error:&error]) {
                    NSLog(@"reating 'upload' directory failed: [%@]", error);
                }

                //    UIImage *image = [UIImage imageNamed:@"Screen Shot 2015-06-16 at 7.25.09 pm"];
                //
                //    NSString *fileName = [[[NSProcessInfo processInfo] globallyUniqueString] stringByAppendingString:@".png"];
                //    NSString *filePath = [[NSTemporaryDirectory() stringByAppendingPathComponent:@"upload"] stringByAppendingPathComponent:fileName];
                //    NSData * imageData = UIImagePNGRepresentation(image);
                //
                //    [imageData writeToFile:filePath atomically:YES];

                NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Untitled" ofType:@"mov"];

                //    NSError *error = nil;
                NSData *data = [NSData dataWithContentsOfFile:filePath];
                if(data == nil && error!=nil) {
                    //Print error description
                }

                AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
                uploadRequest.body = [NSURL fileURLWithPath:filePath];
                uploadRequest.key = @"video1.mov";
                uploadRequest.bucket = S3BucketName;

                [self upload:uploadRequest];
                // Do any additional setup after loading the view, typically from a nib.
            }

For uploading use following method

 - (void)upload:(AWSS3TransferManagerUploadRequest *)uploadRequest {
                        AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];


                        [[transferManager upload:uploadRequest] continueWithBlock:^id(AWSTask *task) {
                            if (task.error) {
                                if ([task.error.domain isEqualToString:AWSS3TransferManagerErrorDomain]) {
                                    switch (task.error.code) {
                                        case AWSS3TransferManagerErrorCancelled:
                                        case AWSS3TransferManagerErrorPaused:
                                        {
                                            dispatch_async(dispatch_get_main_queue(), ^{
                                                //update UI
                                            });
                                        }
                                            break;

                                        default:
                                            NSLog(@"Upload failed: [%@]", task.error);
                                            break;
                                    }
                                } else {
                                    NSLog(@"Upload failed: [%@]", task.error);
                                }
                            }

                            if (task.result) {
                                dispatch_async(dispatch_get_main_queue(), ^{
                                    //Successfully uploaded.
                                    NSLog(@"Successfully uploaded");

                                    //update UI here.
                                });
                            }

                            return nil;
                        }];
                    }