Bolts 框架 continueWithBlock 错误
Bolts framework continueWithBlock error
我使用 AWS s3 已经有一段时间了,直到最近才遇到一些小问题。我通过cocoapods导入框架。最近,我根据 this post.
重新安装了 cocoapods
之后,我遇到了一百万零一次“使用未声明的类型:错误,most in primitive types。我最终通过卸载 cocoapods、重新安装 cocoa[= 解决了这个问题(大部分) 35=],删除,清理,然后为我的特定项目重新安装 pods(还有一堆项目清理)。
我遇到了一个问题,其中没有包含 Bolts(尽管我认为它是 AWSCore 的一部分)。我将 pod Bolts
添加到我的 Podfile 并将 #import <Bolts/Bolts.h>
添加到我的 obj-C -> Swift 桥文件中。
现在,Bolts 已被识别,但我收到一个错误 "Cannot invoke 'continueWithBlock'",参数列表类型为“((BFTask!) -> _)”,代码如下:
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>
最后,我的 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'
关于如何(正如我看到的问题)让 Xcode / Swift 再次正确识别 Bolts/BFTask 有什么想法吗?
在尝试与您相同的步骤后,我通过将 Pods 恢复到上次稳定配置解决了这个确切的问题。
pod 'Bolts', '1.1.5'
pod 'AWSCore', '2.1.1'
pod 'AWSS3', '2.1.1'
不得不这样做很糟糕,但希望这是一个临时的解决方法。我的应用程序现在正在构建和运行良好。希望这对你也有帮助。
您可以使用 AWSTask!代替 BFTask! (它是一个子类)沉默 xcode.
把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;
}];
}
我使用 AWS s3 已经有一段时间了,直到最近才遇到一些小问题。我通过cocoapods导入框架。最近,我根据 this post.
重新安装了 cocoapods之后,我遇到了一百万零一次“使用未声明的类型:错误,most in primitive types。我最终通过卸载 cocoapods、重新安装 cocoa[= 解决了这个问题(大部分) 35=],删除,清理,然后为我的特定项目重新安装 pods(还有一堆项目清理)。
我遇到了一个问题,其中没有包含 Bolts(尽管我认为它是 AWSCore 的一部分)。我将 pod Bolts
添加到我的 Podfile 并将 #import <Bolts/Bolts.h>
添加到我的 obj-C -> Swift 桥文件中。
现在,Bolts 已被识别,但我收到一个错误 "Cannot invoke 'continueWithBlock'",参数列表类型为“((BFTask!) -> _)”,代码如下:
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>
最后,我的 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'
关于如何(正如我看到的问题)让 Xcode / Swift 再次正确识别 Bolts/BFTask 有什么想法吗?
在尝试与您相同的步骤后,我通过将 Pods 恢复到上次稳定配置解决了这个确切的问题。
pod 'Bolts', '1.1.5'
pod 'AWSCore', '2.1.1'
pod 'AWSS3', '2.1.1'
不得不这样做很糟糕,但希望这是一个临时的解决方法。我的应用程序现在正在构建和运行良好。希望这对你也有帮助。
您可以使用 AWSTask!代替 BFTask! (它是一个子类)沉默 xcode.
把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;
}];
}