-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Fix unguarded availability in Camera plugin #2928
Conversation
If you changed it to 10.0 then Flutter apps at 8.0 or 9.0 minimums couldn't use the plugin. There would be a CocoaPods error or a build time error. The dependencies need to have a lower than equal requirement. @dnfield can we get a link to the failure? |
Here's an example: https://cirrus-ci.com/task/5249881340116992 I only noticed the warnings because of an unrelated error that @ditman fixed and I hadn't patched in yet. |
As it is right now, saving a picture to a file on iOS 8.0 or 9.0 would result in a crash. Video functionality would still work. Dropping support for iOS 8.0 and 9.0 might be too severe, but we may want to implement these methods in some way friendly to the version(s) we support if we support them. |
If you get rid of Line 160 in e26634c
|
No, it doesn't pass. |
I'll see if I can fix those. |
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.
Some other warnings:
AVCapturePhotoOutput
andAVCaptureResolvedPhotoSettings
usage (_capturePhotoOutput
,-[captureOutput:::]
) need the same availability treatment.onFrameAvailable
property is missing avoid
@property(nonatomic, copy) void (^onFrameAvailable)(void);
@@ -204,7 +204,7 @@ - (void)startVideoRecordingAtPath:(NSString *)path result:(FlutterResult)result; | |||
- (void)stopVideoRecordingWithResult:(FlutterResult)result; | |||
- (void)startImageStreamWithMessenger:(NSObject<FlutterBinaryMessenger> *)messenger; | |||
- (void)stopImageStream; | |||
- (void)captureToFile:(NSString *)filename result:(FlutterResult)result; | |||
- (void)captureToFile:(NSString *)filename result:(FlutterResult)result API_AVAILABLE(ios(10)); |
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.
All the method declarations can be removed from this interface, it just needs the properties. API_AVAILABLE(ios(10.0))
can go in the implementation:
- (void)captureToFile:(NSString *)path result:(FlutterResult)result API_AVAILABLE(ios(10.0)) {
case AVCaptureDevicePositionUnspecified: | ||
lensFacing = @"external"; | ||
break; | ||
if (@available(iOS 10.0, *)) { |
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.
If call.method is availableCameras
and @available(iOS 10.0, *)
isn't true, should it result(@[]);
? Or do we want the FlutterMethodNotImplemented
(because I guess it isn't, though I don't know the side effects of that)?
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 think FlutterMethodNotImplemented is most appropriate, since we haven't implemented the method for that platform.
Today, this is a hard crash for the end user. At least this way they can handle it in application code.
@@ -847,7 +836,7 @@ - (void)handleMethodCallAsync:(FlutterMethodCall *)call result:(FlutterResult)re | |||
int64_t textureId = [_registry registerTexture:cam]; | |||
_camera = cam; | |||
cam.onFrameAvailable = ^{ | |||
[_registry textureFrameAvailable:textureId]; | |||
[self.registry textureFrameAvailable:textureId]; |
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.
Is this a retain cycle?
One more thing to get rid of the warnings:
Should become: s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' } Like all the other plugins. Example:
That will fix flutter/flutter#61927. |
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.
LGTM, thank you!
} else { | ||
result(FlutterMethodNotImplemented); |
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 think what you had before would have fallen through to FlutterMethodNotImplemented
, whatever you prefer though.
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.
Yeah but it'd make the other else
blocks not run on iOS 10+ :\
Static analyzer error:
Here:
It's being released twice if it hits this codepath:
|
Looks like - (CMSampleBufferRef)adjustTime:(CMSampleBufferRef)sample by:(CMTime)offset CF_RETURNS_RETAINED { or - (CMSampleBufferRef)copyBufferAndAdjustTime:(CMSampleBufferRef)sample by:(CMTime)offset { |
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.
LGTM!
* Fix unguarded availability in Camera plugin
* Fix unguarded availability in Camera plugin
* Fix unguarded availability in Camera plugin
The build is failing on this plugin in an unrelated PR currrently due to these issues.This doesn't fail the build because we're specifically ignoring these warnings, so instead I'm enabling the warnings. This does cause crashes for users on older iOS versions, see linked bug.This does make me wonder if we really should claim to support this plugin on iOS 8.0. Currently, you can't take a picture with the camera plugin on anything lower than iOS 10 - it would cause a runtime crash (now it will just result in an exception that should be recoverable).
Fixes flutter/flutter#20708