Catch and forward iOS exceptions to Flutter
This commit is contained in:
parent
aaa253b133
commit
35a6e4810b
|
@ -84,50 +84,56 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
|
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
|
||||||
NSDictionary *request = (NSDictionary *)call.arguments;
|
@try {
|
||||||
if ([@"load" isEqualToString:call.method]) {
|
NSDictionary *request = (NSDictionary *)call.arguments;
|
||||||
[self load:request[@"audioSource"] result:result];
|
if ([@"load" isEqualToString:call.method]) {
|
||||||
} else if ([@"play" isEqualToString:call.method]) {
|
[self load:request[@"audioSource"] result:result];
|
||||||
[self play:result];
|
} else if ([@"play" isEqualToString:call.method]) {
|
||||||
} else if ([@"pause" isEqualToString:call.method]) {
|
[self play:result];
|
||||||
[self pause];
|
} else if ([@"pause" isEqualToString:call.method]) {
|
||||||
result(@{});
|
[self pause];
|
||||||
} else if ([@"setVolume" isEqualToString:call.method]) {
|
|
||||||
[self setVolume:(float)[request[@"volume"] doubleValue]];
|
|
||||||
result(@{});
|
|
||||||
} else if ([@"setSpeed" isEqualToString:call.method]) {
|
|
||||||
[self setSpeed:(float)[request[@"speed"] doubleValue]];
|
|
||||||
result(@{});
|
|
||||||
} else if ([@"setLoopMode" isEqualToString:call.method]) {
|
|
||||||
[self setLoopMode:[request[@"loopMode"] intValue]];
|
|
||||||
result(@{});
|
|
||||||
} else if ([@"setShuffleMode" isEqualToString:call.method]) {
|
|
||||||
[self setShuffleModeEnabled:(BOOL)([request[@"shuffleMode"] intValue] == 1)];
|
|
||||||
result(@{});
|
|
||||||
} else if ([@"setAutomaticallyWaitsToMinimizeStalling" isEqualToString:call.method]) {
|
|
||||||
[self setAutomaticallyWaitsToMinimizeStalling:(BOOL)[request[@"enabled"] boolValue]];
|
|
||||||
result(@{});
|
|
||||||
} else if ([@"seek" isEqualToString:call.method]) {
|
|
||||||
CMTime position = request[@"position"] == [NSNull null] ? kCMTimePositiveInfinity : CMTimeMake([request[@"position"] longLongValue], 1000000);
|
|
||||||
[self seek:position index:request[@"index"] completionHandler:^(BOOL finished) {
|
|
||||||
result(@{});
|
result(@{});
|
||||||
}];
|
} else if ([@"setVolume" isEqualToString:call.method]) {
|
||||||
} else if ([@"dispose" isEqualToString:call.method]) {
|
[self setVolume:(float)[request[@"volume"] doubleValue]];
|
||||||
[self dispose];
|
result(@{});
|
||||||
result(@{});
|
} else if ([@"setSpeed" isEqualToString:call.method]) {
|
||||||
} else if ([@"concatenatingInsertAll" isEqualToString:call.method]) {
|
[self setSpeed:(float)[request[@"speed"] doubleValue]];
|
||||||
[self concatenatingInsertAll:(NSString *)request[@"id"] index:[request[@"index"] intValue] sources:(NSArray *)request[@"children"]];
|
result(@{});
|
||||||
result(@{});
|
} else if ([@"setLoopMode" isEqualToString:call.method]) {
|
||||||
} else if ([@"concatenatingRemoveRange" isEqualToString:call.method]) {
|
[self setLoopMode:[request[@"loopMode"] intValue]];
|
||||||
[self concatenatingRemoveRange:(NSString *)request[@"id"] start:[request[@"startIndex"] intValue] end:[request[@"endIndex"] intValue]];
|
result(@{});
|
||||||
result(@{});
|
} else if ([@"setShuffleMode" isEqualToString:call.method]) {
|
||||||
} else if ([@"concatenatingMove" isEqualToString:call.method]) {
|
[self setShuffleModeEnabled:(BOOL)([request[@"shuffleMode"] intValue] == 1)];
|
||||||
[self concatenatingMove:(NSString *)request[@"id"] currentIndex:[request[@"currentIndex"] intValue] newIndex:[request[@"newIndex"] intValue]];
|
result(@{});
|
||||||
result(@{});
|
} else if ([@"setAutomaticallyWaitsToMinimizeStalling" isEqualToString:call.method]) {
|
||||||
} else if ([@"setAndroidAudioAttributes" isEqualToString:call.method]) {
|
[self setAutomaticallyWaitsToMinimizeStalling:(BOOL)[request[@"enabled"] boolValue]];
|
||||||
result(@{});
|
result(@{});
|
||||||
} else {
|
} else if ([@"seek" isEqualToString:call.method]) {
|
||||||
result(FlutterMethodNotImplemented);
|
CMTime position = request[@"position"] == [NSNull null] ? kCMTimePositiveInfinity : CMTimeMake([request[@"position"] longLongValue], 1000000);
|
||||||
|
[self seek:position index:request[@"index"] completionHandler:^(BOOL finished) {
|
||||||
|
result(@{});
|
||||||
|
}];
|
||||||
|
} else if ([@"dispose" isEqualToString:call.method]) {
|
||||||
|
[self dispose];
|
||||||
|
result(@{});
|
||||||
|
} else if ([@"concatenatingInsertAll" isEqualToString:call.method]) {
|
||||||
|
[self concatenatingInsertAll:(NSString *)request[@"id"] index:[request[@"index"] intValue] sources:(NSArray *)request[@"children"]];
|
||||||
|
result(@{});
|
||||||
|
} else if ([@"concatenatingRemoveRange" isEqualToString:call.method]) {
|
||||||
|
[self concatenatingRemoveRange:(NSString *)request[@"id"] start:[request[@"startIndex"] intValue] end:[request[@"endIndex"] intValue]];
|
||||||
|
result(@{});
|
||||||
|
} else if ([@"concatenatingMove" isEqualToString:call.method]) {
|
||||||
|
[self concatenatingMove:(NSString *)request[@"id"] currentIndex:[request[@"currentIndex"] intValue] newIndex:[request[@"newIndex"] intValue]];
|
||||||
|
result(@{});
|
||||||
|
} else if ([@"setAndroidAudioAttributes" isEqualToString:call.method]) {
|
||||||
|
result(@{});
|
||||||
|
} else {
|
||||||
|
result(FlutterMethodNotImplemented);
|
||||||
|
}
|
||||||
|
} @catch (id exception) {
|
||||||
|
NSLog(@"Error in handleMethodCall");
|
||||||
|
FlutterError *flutterError = [FlutterError errorWithCode:@"error" message:@"Error in handleMethodCall" details:nil];
|
||||||
|
result(flutterError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue