-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[camera] Remove @throw
from iOS implementation
#5034
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ - (void)testFLTGetFLTFlashModeForString { | |
XCTAssertEqual(FLTFlashModeAuto, FLTGetFLTFlashModeForString(@"auto")); | ||
XCTAssertEqual(FLTFlashModeAlways, FLTGetFLTFlashModeForString(@"always")); | ||
XCTAssertEqual(FLTFlashModeTorch, FLTGetFLTFlashModeForString(@"torch")); | ||
XCTAssertThrows(FLTGetFLTFlashModeForString(@"unkwown")); | ||
XCTAssertEqual(FLTFlashModeInvalid, FLTGetFLTFlashModeForString(@"unknown")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: should it be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we have a new flash mode in the future then we need to update both the Dart and Obj-C code at the same time. This code is purely for manual platform channel conversions, which means the only way to get a value we don't recognize is if someone adds serialization for that mode on the Dart side but not the corresponding deserialization code on the native side, which would make no sense. If we have flash modes that the Dart side of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (This is why Pigeon will moot all of this; in Pigeon it's impossible for an enum value defined in the interface to exist on one side but not the other.) |
||
} | ||
|
||
- (void)testFLTGetAVCaptureFlashModeForFLTFlashMode { | ||
|
@@ -34,27 +34,27 @@ - (void)testFLTGetAVCaptureFlashModeForFLTFlashMode { | |
- (void)testFLTGetStringForFLTExposureMode { | ||
XCTAssertEqualObjects(@"auto", FLTGetStringForFLTExposureMode(FLTExposureModeAuto)); | ||
XCTAssertEqualObjects(@"locked", FLTGetStringForFLTExposureMode(FLTExposureModeLocked)); | ||
XCTAssertThrows(FLTGetStringForFLTExposureMode(-1)); | ||
XCTAssertNil(FLTGetStringForFLTExposureMode(-1)); | ||
} | ||
|
||
- (void)testFLTGetFLTExposureModeForString { | ||
XCTAssertEqual(FLTExposureModeAuto, FLTGetFLTExposureModeForString(@"auto")); | ||
XCTAssertEqual(FLTExposureModeLocked, FLTGetFLTExposureModeForString(@"locked")); | ||
XCTAssertThrows(FLTGetFLTExposureModeForString(@"unknown")); | ||
XCTAssertEqual(FLTExposureModeInvalid, FLTGetFLTExposureModeForString(@"unknown")); | ||
} | ||
|
||
#pragma mark - focus mode tests | ||
|
||
- (void)testFLTGetStringForFLTFocusMode { | ||
XCTAssertEqualObjects(@"auto", FLTGetStringForFLTFocusMode(FLTFocusModeAuto)); | ||
XCTAssertEqualObjects(@"locked", FLTGetStringForFLTFocusMode(FLTFocusModeLocked)); | ||
XCTAssertThrows(FLTGetStringForFLTFocusMode(-1)); | ||
XCTAssertNil(FLTGetStringForFLTFocusMode(-1)); | ||
} | ||
|
||
- (void)testFLTGetFLTFocusModeForString { | ||
XCTAssertEqual(FLTFocusModeAuto, FLTGetFLTFocusModeForString(@"auto")); | ||
XCTAssertEqual(FLTFocusModeLocked, FLTGetFLTFocusModeForString(@"locked")); | ||
XCTAssertThrows(FLTGetFLTFocusModeForString(@"unknown")); | ||
XCTAssertEqual(FLTFocusModeInvalid, FLTGetFLTFocusModeForString(@"unknown")); | ||
} | ||
|
||
#pragma mark - resolution preset tests | ||
|
@@ -67,7 +67,7 @@ - (void)testFLTGetFLTResolutionPresetForString { | |
XCTAssertEqual(FLTResolutionPresetVeryHigh, FLTGetFLTResolutionPresetForString(@"veryHigh")); | ||
XCTAssertEqual(FLTResolutionPresetUltraHigh, FLTGetFLTResolutionPresetForString(@"ultraHigh")); | ||
XCTAssertEqual(FLTResolutionPresetMax, FLTGetFLTResolutionPresetForString(@"max")); | ||
XCTAssertThrows(FLTGetFLTFlashModeForString(@"unknown")); | ||
XCTAssertEqual(FLTResolutionPresetInvalid, FLTGetFLTResolutionPresetForString(@"unknown")); | ||
} | ||
|
||
#pragma mark - video format tests | ||
|
@@ -89,7 +89,7 @@ - (void)testFLTGetUIDeviceOrientationForString { | |
XCTAssertEqual(UIDeviceOrientationLandscapeLeft, | ||
FLTGetUIDeviceOrientationForString(@"landscapeRight")); | ||
XCTAssertEqual(UIDeviceOrientationPortrait, FLTGetUIDeviceOrientationForString(@"portraitUp")); | ||
XCTAssertThrows(FLTGetUIDeviceOrientationForString(@"unknown")); | ||
XCTAssertEqual(UIDeviceOrientationUnknown, FLTGetUIDeviceOrientationForString(@"unknown")); | ||
} | ||
|
||
- (void)testFLTGetStringForUIDeviceOrientation { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,10 +118,16 @@ - (instancetype)initWithCameraName:(NSString *)cameraName | |
error:(NSError **)error { | ||
self = [super init]; | ||
NSAssert(self, @"super init cannot be nil"); | ||
@try { | ||
_resolutionPreset = FLTGetFLTResolutionPresetForString(resolutionPreset); | ||
} @catch (NSError *e) { | ||
*error = e; | ||
_resolutionPreset = FLTGetFLTResolutionPresetForString(resolutionPreset); | ||
if (_resolutionPreset == FLTResolutionPresetInvalid) { | ||
*error = [NSError | ||
errorWithDomain:NSCocoaErrorDomain | ||
code:NSURLErrorUnknown | ||
userInfo:@{ | ||
NSLocalizedDescriptionKey : | ||
[NSString stringWithFormat:@"Unknown resolution preset %@", resolutionPreset] | ||
}]; | ||
return nil; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is technically a behavioral change since not returning |
||
} | ||
_enableAudio = enableAudio; | ||
_captureSessionQueue = captureSessionQueue; | ||
|
@@ -162,7 +168,9 @@ - (instancetype)initWithCameraName:(NSString *)cameraName | |
_motionManager = [[CMMotionManager alloc] init]; | ||
[_motionManager startAccelerometerUpdates]; | ||
|
||
[self setCaptureSessionPreset:_resolutionPreset]; | ||
if (![self setCaptureSessionPreset:_resolutionPreset withError:error]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also technically a behavioral change in that now the error actually gets returned instead of us having an unhandled But as above, this should not actually be a thing that can happen as far as I can tell. |
||
return nil; | ||
} | ||
[self updateOrientation]; | ||
|
||
return self; | ||
|
@@ -337,7 +345,7 @@ - (NSString *)getTemporaryFilePathWithExtension:(NSString *)extension | |
return file; | ||
} | ||
|
||
- (void)setCaptureSessionPreset:(FLTResolutionPreset)resolutionPreset { | ||
- (BOOL)setCaptureSessionPreset:(FLTResolutionPreset)resolutionPreset withError:(NSError **)error { | ||
switch (resolutionPreset) { | ||
case FLTResolutionPresetMax: | ||
case FLTResolutionPresetUltraHigh: | ||
|
@@ -382,17 +390,17 @@ - (void)setCaptureSessionPreset:(FLTResolutionPreset)resolutionPreset { | |
_videoCaptureSession.sessionPreset = AVCaptureSessionPresetLow; | ||
_previewSize = CGSizeMake(352, 288); | ||
} else { | ||
NSError *error = | ||
[NSError errorWithDomain:NSCocoaErrorDomain | ||
code:NSURLErrorUnknown | ||
userInfo:@{ | ||
NSLocalizedDescriptionKey : | ||
@"No capture session available for current capture session." | ||
}]; | ||
@throw error; | ||
*error = [NSError errorWithDomain:NSCocoaErrorDomain | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of these NSErrors are directly moved from the code that was This was some deeply strange Obj-C code. |
||
code:NSURLErrorUnknown | ||
userInfo:@{ | ||
NSLocalizedDescriptionKey : | ||
@"No capture session available for current capture session." | ||
}]; | ||
return NO; | ||
} | ||
} | ||
_audioCaptureSession.sessionPreset = _videoCaptureSession.sessionPreset; | ||
return YES; | ||
} | ||
|
||
- (void)captureOutput:(AVCaptureOutput *)output | ||
|
@@ -726,11 +734,17 @@ - (void)resumeVideoRecordingWithResult:(FLTThreadSafeFlutterResult *)result { | |
|
||
- (void)lockCaptureOrientationWithResult:(FLTThreadSafeFlutterResult *)result | ||
orientation:(NSString *)orientationStr { | ||
UIDeviceOrientation orientation; | ||
@try { | ||
orientation = FLTGetUIDeviceOrientationForString(orientationStr); | ||
} @catch (NSError *e) { | ||
[result sendError:e]; | ||
UIDeviceOrientation orientation = FLTGetUIDeviceOrientationForString(orientationStr); | ||
// "Unknown" should never be sent, so is used to represent an unexpected | ||
// value. | ||
if (orientation == UIDeviceOrientationUnknown) { | ||
[result sendError:[NSError errorWithDomain:NSCocoaErrorDomain | ||
code:NSURLErrorUnknown | ||
userInfo:@{ | ||
NSLocalizedDescriptionKey : [NSString | ||
stringWithFormat:@"Unknown device orientation %@", | ||
orientationStr] | ||
}]]; | ||
return; | ||
} | ||
|
||
|
@@ -749,11 +763,14 @@ - (void)unlockCaptureOrientationWithResult:(FLTThreadSafeFlutterResult *)result | |
} | ||
|
||
- (void)setFlashModeWithResult:(FLTThreadSafeFlutterResult *)result mode:(NSString *)modeStr { | ||
FLTFlashMode mode; | ||
@try { | ||
mode = FLTGetFLTFlashModeForString(modeStr); | ||
} @catch (NSError *e) { | ||
[result sendError:e]; | ||
FLTFlashMode mode = FLTGetFLTFlashModeForString(modeStr); | ||
if (mode == FLTFlashModeInvalid) { | ||
[result sendError:[NSError errorWithDomain:NSCocoaErrorDomain | ||
code:NSURLErrorUnknown | ||
userInfo:@{ | ||
NSLocalizedDescriptionKey : [NSString | ||
stringWithFormat:@"Unknown flash mode %@", modeStr] | ||
}]]; | ||
return; | ||
} | ||
if (mode == FLTFlashModeTorch) { | ||
|
@@ -800,11 +817,14 @@ - (void)setFlashModeWithResult:(FLTThreadSafeFlutterResult *)result mode:(NSStri | |
} | ||
|
||
- (void)setExposureModeWithResult:(FLTThreadSafeFlutterResult *)result mode:(NSString *)modeStr { | ||
FLTExposureMode mode; | ||
@try { | ||
mode = FLTGetFLTExposureModeForString(modeStr); | ||
} @catch (NSError *e) { | ||
[result sendError:e]; | ||
FLTExposureMode mode = FLTGetFLTExposureModeForString(modeStr); | ||
if (mode == FLTExposureModeInvalid) { | ||
[result sendError:[NSError errorWithDomain:NSCocoaErrorDomain | ||
code:NSURLErrorUnknown | ||
userInfo:@{ | ||
NSLocalizedDescriptionKey : [NSString | ||
stringWithFormat:@"Unknown exposure mode %@", modeStr] | ||
}]]; | ||
return; | ||
} | ||
_exposureMode = mode; | ||
|
@@ -830,11 +850,14 @@ - (void)applyExposureMode { | |
} | ||
|
||
- (void)setFocusModeWithResult:(FLTThreadSafeFlutterResult *)result mode:(NSString *)modeStr { | ||
FLTFocusMode mode; | ||
@try { | ||
mode = FLTGetFLTFocusModeForString(modeStr); | ||
} @catch (NSError *e) { | ||
[result sendError:e]; | ||
FLTFocusMode mode = FLTGetFLTFocusModeForString(modeStr); | ||
if (mode == FLTFocusModeInvalid) { | ||
[result sendError:[NSError errorWithDomain:NSCocoaErrorDomain | ||
code:NSURLErrorUnknown | ||
userInfo:@{ | ||
NSLocalizedDescriptionKey : [NSString | ||
stringWithFormat:@"Unknown focus mode %@", modeStr] | ||
}]]; | ||
return; | ||
} | ||
_focusMode = mode; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: ... cause crashes on launch on iOS 17
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I unfortunately don't know if it's "on iOS 17" or "when compiled against the iOS 17 SDK" or some other slight variant of that, which is why I left it vague.