我从 github 下载了 Drupal-iOS-SDK 我还下载了 AFNetworking 文件 from here .
然后我将文件添加到我的项目中,但它显示了一个奇怪的错误
Incompatible block pointer types sending 'void (^)(NSInteger, NSInteger, NSInteger)' to parameter of type 'void (^)(NSInteger, long long, long long)'
对于这段代码:
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setUploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {
NSLog(@"Sent %d of %d bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
有人知道这意味着什么吗?
最佳答案
您正在将三个 NSInteger
作为参数发送给 setUploadProgressBlock
,而预期需要一个 NSUInteger
(无符号整数)和两个 long long
参数
totalBytesWritten
和 totalBytesExpectedToWrite
需要为 long long
类型,因为这就是它们的定义方式,而不是 `NSInteger' 的定义方式。您的代码应该如下所示:
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
NSLog(@"Sent %d of %d bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
您可能还想相应地修改您的 NSLog,因为它已设置为 long long
,这样编译器就不会提示。
NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
关于iphone - drupal-ios-sdk 与 iPhone 应用程序集成时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12350464/