我发现了很多有关使用方法通道将数据从flutter传递到android的信息,但没有关于目标c的信息。我了解调用函数,但不传递数据。以下是我所拥有的示例。
Future<void> _uploadImage(String filePath) async {
try {
await platform.invokeMethod('uploadImage', {"filePath": filePath});
} on PlatformException catch (e) {
print("Failed to get token: '${e.message}'.");
}
}
else if([@"uploadImage" isEqualToString:call.method]){
DBUserClient *client = [DBClientsManager authorizedClient];
NSString *filePath = call.arguments(@"filePath");
NSLog(filePath, result);
NSData *fileData = [filePath dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
[[[client.filesRoutes uploadData:filePath inputData:fileData]
setResponseBlock:^(DBFILESFileMetadata *result, DBFILESUploadError *routeError, DBRequestError *networkError) {
if (result)
{
NSLog(@"%@\n", result);
} else
{
NSLog(@"%@\n%@\n", routeError, networkError);
}
}] setProgressBlock:^(int64_t bytesUploaded, int64_t totalBytesUploaded, int64_t totalBytesExpectedToUploaded) {
NSLog(@"\n%lld\n%lld\n%lld\n", bytesUploaded, totalBytesUploaded, totalBytesExpectedToUploaded);
}];
}
else{
result(FlutterMethodNotImplemented);
}
}];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
澄清一下,用objective-c编写的最底层代码绝对是不正确的,但是我一直在努力弄清楚。我有图片路径,并且尝试将其上传到Dropbox。主要问题是filePath没有到达方法通道。 NSString * filePath = call.arguments(@“ filePath”)不是实际的函数调用。
答案 0 :(得分:1)
更改:
NSString *filePath = call.arguments(@"filePath");
到
NSString *filePath = call.arguments[@"filePath"];