2

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?

4

3 回答 3

4

您可以使用 AWSTask!代替BFTask!(它是一个子类)使 xcode 静音。

于 2015-08-25T15:38:34.743 回答
2

在尝试了与您相同的步骤后,我通过将我的 Pod 恢复到我最后的稳定配置来解决这个确切的头部问题。

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

不得不这样做很糟糕,但希望这是一个临时的解决方法。我的应用程序现在正在构建和运行良好。希望这对你也有帮助。

于 2015-06-24T17:33:04.297 回答
1

只需将 BFTask 的单词替换为 AWSTask 即可。

导入以下文件和框架

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

在此处提供文件路径

   - (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.
            }

上传使用以下方法

 - (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;
                        }];
                    }
于 2015-12-11T07:01:06.387 回答