@@ -69,6 +69,7 @@ void generateObjcHeader(ObjcOptions options, Root root, StringSink sink) {
6969 indent.writeln ('// $seeAlsoWarning ' );
7070 indent.writeln ('#import <Foundation/Foundation.h>' );
7171 indent.writeln ('@protocol FlutterBinaryMessenger;' );
72+ indent.writeln ('@class FlutterError;' );
7273 indent.writeln ('@class FlutterStandardTypedData;' );
7374 indent.writeln ('' );
7475
@@ -104,7 +105,8 @@ void generateObjcHeader(ObjcOptions options, Root root, StringSink sink) {
104105 for (Method func in api.methods) {
105106 final String returnType = _className (options.prefix, func.returnType);
106107 final String argType = _className (options.prefix, func.argType);
107- indent.writeln ('-($returnType *)${func .name }:($argType *)input;' );
108+ indent.writeln (
109+ '-($returnType *)${func .name }:($argType *)input error:(FlutterError **)error;' );
108110 }
109111 indent.writeln ('@end' );
110112 indent.writeln ('' );
@@ -175,8 +177,10 @@ void _writeHostApiSource(Indent indent, ObjcOptions options, Api api) {
175177 final String returnType =
176178 _className (options.prefix, func.returnType);
177179 indent.writeln ('$argType *input = [$argType fromMap:message];' );
178- indent.writeln ('$returnType *output = [api ${func .name }:input];' );
179- indent.writeln ('callback([output toMap]);' );
180+ indent.writeln ('FlutterError *error;' );
181+ indent.writeln (
182+ '$returnType *output = [api ${func .name }:input error:&error];' );
183+ indent.writeln ('callback(wrapResult([output toMap], error));' );
180184 });
181185 });
182186 indent.write ('else ' );
@@ -247,6 +251,28 @@ void generateObjcSource(ObjcOptions options, Root root, StringSink sink) {
247251 indent.writeln ('#import <Flutter/Flutter.h>' );
248252 indent.writeln ('' );
249253
254+ indent.writeln ('#if !__has_feature(objc_arc)' );
255+ indent.writeln ('#error File requires ARC to be enabled.' );
256+ indent.writeln ('#endif' );
257+ indent.addln ('' );
258+
259+ indent.format (
260+ '''static NSDictionary* wrapResult(NSDictionary *result, FlutterError *error) {
261+ \t NSDictionary *errorDict = (NSDictionary *)[NSNull null];
262+ \t if (error) {
263+ \t\t errorDict = [NSDictionary dictionaryWithObjectsAndKeys:
264+ \t\t\t\t (error.code ? error.code : [NSNull null]), @"${Keys .errorCode }",
265+ \t\t\t\t (error.message ? error.message : [NSNull null]), @"${Keys .errorMessage }",
266+ \t\t\t\t (error.details ? error.details : [NSNull null]), @"${Keys .errorDetails }",
267+ \t\t\t\t nil];
268+ \t }
269+ \t return [NSDictionary dictionaryWithObjectsAndKeys:
270+ \t\t\t (result ? result : [NSNull null]), @"${Keys .result }",
271+ \t\t\t errorDict, @"${Keys .error }",
272+ \t\t\t nil];
273+ }''' );
274+ indent.addln ('' );
275+
250276 for (Class klass in root.classes) {
251277 final String className = _className (options.prefix, klass.name);
252278 indent.writeln ('@interface $className ()' );
0 commit comments