1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct UIImagePickerControllerSourceType(pub NSInteger);
17impl UIImagePickerControllerSourceType {
18 #[doc(alias = "UIImagePickerControllerSourceTypePhotoLibrary")]
19 #[deprecated = "Will be removed in a future release, use PHPicker."]
20 pub const PhotoLibrary: Self = Self(0);
21 #[doc(alias = "UIImagePickerControllerSourceTypeCamera")]
22 pub const Camera: Self = Self(1);
23 #[doc(alias = "UIImagePickerControllerSourceTypeSavedPhotosAlbum")]
24 #[deprecated = "Will be removed in a future release, use PHPicker."]
25 pub const SavedPhotosAlbum: Self = Self(2);
26}
27
28unsafe impl Encode for UIImagePickerControllerSourceType {
29 const ENCODING: Encoding = NSInteger::ENCODING;
30}
31
32unsafe impl RefEncode for UIImagePickerControllerSourceType {
33 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
34}
35
36#[repr(transparent)]
39#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
40pub struct UIImagePickerControllerQualityType(pub NSInteger);
41impl UIImagePickerControllerQualityType {
42 #[doc(alias = "UIImagePickerControllerQualityTypeHigh")]
43 pub const TypeHigh: Self = Self(0);
44 #[doc(alias = "UIImagePickerControllerQualityTypeMedium")]
45 pub const TypeMedium: Self = Self(1);
46 #[doc(alias = "UIImagePickerControllerQualityTypeLow")]
47 pub const TypeLow: Self = Self(2);
48 #[doc(alias = "UIImagePickerControllerQualityType640x480")]
49 pub const Type640x480: Self = Self(3);
50 #[doc(alias = "UIImagePickerControllerQualityTypeIFrame1280x720")]
51 pub const TypeIFrame1280x720: Self = Self(4);
52 #[doc(alias = "UIImagePickerControllerQualityTypeIFrame960x540")]
53 pub const TypeIFrame960x540: Self = Self(5);
54}
55
56unsafe impl Encode for UIImagePickerControllerQualityType {
57 const ENCODING: Encoding = NSInteger::ENCODING;
58}
59
60unsafe impl RefEncode for UIImagePickerControllerQualityType {
61 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
62}
63
64#[repr(transparent)]
67#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
68pub struct UIImagePickerControllerCameraCaptureMode(pub NSInteger);
69impl UIImagePickerControllerCameraCaptureMode {
70 #[doc(alias = "UIImagePickerControllerCameraCaptureModePhoto")]
71 pub const Photo: Self = Self(0);
72 #[doc(alias = "UIImagePickerControllerCameraCaptureModeVideo")]
73 pub const Video: Self = Self(1);
74}
75
76unsafe impl Encode for UIImagePickerControllerCameraCaptureMode {
77 const ENCODING: Encoding = NSInteger::ENCODING;
78}
79
80unsafe impl RefEncode for UIImagePickerControllerCameraCaptureMode {
81 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
82}
83
84#[repr(transparent)]
87#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
88pub struct UIImagePickerControllerCameraDevice(pub NSInteger);
89impl UIImagePickerControllerCameraDevice {
90 #[doc(alias = "UIImagePickerControllerCameraDeviceRear")]
91 pub const Rear: Self = Self(0);
92 #[doc(alias = "UIImagePickerControllerCameraDeviceFront")]
93 pub const Front: Self = Self(1);
94}
95
96unsafe impl Encode for UIImagePickerControllerCameraDevice {
97 const ENCODING: Encoding = NSInteger::ENCODING;
98}
99
100unsafe impl RefEncode for UIImagePickerControllerCameraDevice {
101 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
102}
103
104#[repr(transparent)]
107#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
108pub struct UIImagePickerControllerCameraFlashMode(pub NSInteger);
109impl UIImagePickerControllerCameraFlashMode {
110 #[doc(alias = "UIImagePickerControllerCameraFlashModeOff")]
111 pub const Off: Self = Self(-1);
112 #[doc(alias = "UIImagePickerControllerCameraFlashModeAuto")]
113 pub const Auto: Self = Self(0);
114 #[doc(alias = "UIImagePickerControllerCameraFlashModeOn")]
115 pub const On: Self = Self(1);
116}
117
118unsafe impl Encode for UIImagePickerControllerCameraFlashMode {
119 const ENCODING: Encoding = NSInteger::ENCODING;
120}
121
122unsafe impl RefEncode for UIImagePickerControllerCameraFlashMode {
123 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
124}
125
126#[deprecated = "Will be removed in a future release, use PHPicker."]
129#[repr(transparent)]
130#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
131pub struct UIImagePickerControllerImageURLExportPreset(pub NSInteger);
132impl UIImagePickerControllerImageURLExportPreset {
133 #[doc(alias = "UIImagePickerControllerImageURLExportPresetCompatible")]
134 #[deprecated = "Will be removed in a future release, use PHPicker."]
135 pub const Compatible: Self = Self(0);
136 #[doc(alias = "UIImagePickerControllerImageURLExportPresetCurrent")]
137 #[deprecated = "Will be removed in a future release, use PHPicker."]
138 pub const Current: Self = Self(1);
139}
140
141unsafe impl Encode for UIImagePickerControllerImageURLExportPreset {
142 const ENCODING: Encoding = NSInteger::ENCODING;
143}
144
145unsafe impl RefEncode for UIImagePickerControllerImageURLExportPreset {
146 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
147}
148
149pub type UIImagePickerControllerInfoKey = NSString;
152
153extern "C" {
154 pub static UIImagePickerControllerMediaType: &'static UIImagePickerControllerInfoKey;
156}
157
158extern "C" {
159 pub static UIImagePickerControllerOriginalImage: &'static UIImagePickerControllerInfoKey;
161}
162
163extern "C" {
164 pub static UIImagePickerControllerEditedImage: &'static UIImagePickerControllerInfoKey;
166}
167
168extern "C" {
169 pub static UIImagePickerControllerCropRect: &'static UIImagePickerControllerInfoKey;
171}
172
173extern "C" {
174 pub static UIImagePickerControllerMediaURL: &'static UIImagePickerControllerInfoKey;
176}
177
178extern "C" {
179 #[deprecated = "Will be removed in a future release, use PHPicker."]
181 pub static UIImagePickerControllerReferenceURL: &'static UIImagePickerControllerInfoKey;
182}
183
184extern "C" {
185 pub static UIImagePickerControllerMediaMetadata: &'static UIImagePickerControllerInfoKey;
187}
188
189extern "C" {
190 pub static UIImagePickerControllerLivePhoto: &'static UIImagePickerControllerInfoKey;
192}
193
194extern "C" {
195 #[deprecated = "Will be removed in a future release, use PHPicker."]
197 pub static UIImagePickerControllerPHAsset: &'static UIImagePickerControllerInfoKey;
198}
199
200extern "C" {
201 pub static UIImagePickerControllerImageURL: &'static UIImagePickerControllerInfoKey;
203}
204
205extern_class!(
206 #[unsafe(super(UINavigationController, UIViewController, UIResponder, NSObject))]
208 #[thread_kind = MainThreadOnly]
209 #[derive(Debug, PartialEq, Eq, Hash)]
210 #[cfg(all(
211 feature = "UINavigationController",
212 feature = "UIResponder",
213 feature = "UIViewController"
214 ))]
215 pub struct UIImagePickerController;
216);
217
218#[cfg(all(
219 feature = "UINavigationController",
220 feature = "UIResponder",
221 feature = "UIViewController"
222))]
223extern_conformance!(
224 unsafe impl NSCoding for UIImagePickerController {}
225);
226
227#[cfg(all(
228 feature = "UINavigationController",
229 feature = "UIResponder",
230 feature = "UIViewController"
231))]
232extern_conformance!(
233 unsafe impl NSObjectProtocol for UIImagePickerController {}
234);
235
236#[cfg(all(
237 feature = "UIAppearance",
238 feature = "UINavigationController",
239 feature = "UIResponder",
240 feature = "UIViewController"
241))]
242extern_conformance!(
243 unsafe impl UIAppearanceContainer for UIImagePickerController {}
244);
245
246#[cfg(all(
247 feature = "UINavigationController",
248 feature = "UIResponder",
249 feature = "UIViewController"
250))]
251extern_conformance!(
252 unsafe impl UIContentContainer for UIImagePickerController {}
253);
254
255#[cfg(all(
256 feature = "UIFocus",
257 feature = "UINavigationController",
258 feature = "UIResponder",
259 feature = "UIViewController"
260))]
261extern_conformance!(
262 unsafe impl UIFocusEnvironment for UIImagePickerController {}
263);
264
265#[cfg(all(
266 feature = "UINavigationController",
267 feature = "UIResponder",
268 feature = "UIViewController"
269))]
270extern_conformance!(
271 unsafe impl UIResponderStandardEditActions for UIImagePickerController {}
272);
273
274#[cfg(all(
275 feature = "UINavigationController",
276 feature = "UIResponder",
277 feature = "UITraitCollection",
278 feature = "UIViewController"
279))]
280extern_conformance!(
281 unsafe impl UITraitEnvironment for UIImagePickerController {}
282);
283
284#[cfg(all(
285 feature = "UINavigationController",
286 feature = "UIResponder",
287 feature = "UIViewController"
288))]
289impl UIImagePickerController {
290 extern_methods!(
291 #[unsafe(method(isSourceTypeAvailable:))]
292 #[unsafe(method_family = none)]
293 pub fn isSourceTypeAvailable(
294 source_type: UIImagePickerControllerSourceType,
295 mtm: MainThreadMarker,
296 ) -> bool;
297
298 #[unsafe(method(availableMediaTypesForSourceType:))]
299 #[unsafe(method_family = none)]
300 pub fn availableMediaTypesForSourceType(
301 source_type: UIImagePickerControllerSourceType,
302 mtm: MainThreadMarker,
303 ) -> Option<Retained<NSArray<NSString>>>;
304
305 #[unsafe(method(isCameraDeviceAvailable:))]
306 #[unsafe(method_family = none)]
307 pub fn isCameraDeviceAvailable(
308 camera_device: UIImagePickerControllerCameraDevice,
309 mtm: MainThreadMarker,
310 ) -> bool;
311
312 #[unsafe(method(isFlashAvailableForCameraDevice:))]
313 #[unsafe(method_family = none)]
314 pub fn isFlashAvailableForCameraDevice(
315 camera_device: UIImagePickerControllerCameraDevice,
316 mtm: MainThreadMarker,
317 ) -> bool;
318
319 #[unsafe(method(availableCaptureModesForCameraDevice:))]
320 #[unsafe(method_family = none)]
321 pub fn availableCaptureModesForCameraDevice(
322 camera_device: UIImagePickerControllerCameraDevice,
323 mtm: MainThreadMarker,
324 ) -> Option<Retained<NSArray<NSNumber>>>;
325
326 #[unsafe(method(delegate))]
327 #[unsafe(method_family = none)]
328 pub fn delegate(
329 &self,
330 ) -> Option<
331 Retained<
332 AnyObject, >,
334 >;
335
336 #[unsafe(method(setDelegate:))]
344 #[unsafe(method_family = none)]
345 pub unsafe fn setDelegate(
346 &self,
347 delegate: Option<
348 &AnyObject, >,
350 );
351
352 #[unsafe(method(sourceType))]
353 #[unsafe(method_family = none)]
354 pub fn sourceType(&self) -> UIImagePickerControllerSourceType;
355
356 #[unsafe(method(setSourceType:))]
358 #[unsafe(method_family = none)]
359 pub fn setSourceType(&self, source_type: UIImagePickerControllerSourceType);
360
361 #[unsafe(method(mediaTypes))]
362 #[unsafe(method_family = none)]
363 pub fn mediaTypes(&self) -> Retained<NSArray<NSString>>;
364
365 #[unsafe(method(setMediaTypes:))]
369 #[unsafe(method_family = none)]
370 pub fn setMediaTypes(&self, media_types: &NSArray<NSString>);
371
372 #[unsafe(method(allowsEditing))]
373 #[unsafe(method_family = none)]
374 pub fn allowsEditing(&self) -> bool;
375
376 #[unsafe(method(setAllowsEditing:))]
378 #[unsafe(method_family = none)]
379 pub fn setAllowsEditing(&self, allows_editing: bool);
380
381 #[deprecated]
382 #[unsafe(method(allowsImageEditing))]
383 #[unsafe(method_family = none)]
384 pub fn allowsImageEditing(&self) -> bool;
385
386 #[deprecated]
388 #[unsafe(method(setAllowsImageEditing:))]
389 #[unsafe(method_family = none)]
390 pub fn setAllowsImageEditing(&self, allows_image_editing: bool);
391
392 #[deprecated = "Will be removed in a future release, use PHPicker."]
393 #[unsafe(method(imageExportPreset))]
394 #[unsafe(method_family = none)]
395 pub fn imageExportPreset(&self) -> UIImagePickerControllerImageURLExportPreset;
396
397 #[deprecated = "Will be removed in a future release, use PHPicker."]
399 #[unsafe(method(setImageExportPreset:))]
400 #[unsafe(method_family = none)]
401 pub fn setImageExportPreset(
402 &self,
403 image_export_preset: UIImagePickerControllerImageURLExportPreset,
404 );
405
406 #[unsafe(method(videoMaximumDuration))]
407 #[unsafe(method_family = none)]
408 pub fn videoMaximumDuration(&self) -> NSTimeInterval;
409
410 #[unsafe(method(setVideoMaximumDuration:))]
412 #[unsafe(method_family = none)]
413 pub fn setVideoMaximumDuration(&self, video_maximum_duration: NSTimeInterval);
414
415 #[unsafe(method(videoQuality))]
416 #[unsafe(method_family = none)]
417 pub fn videoQuality(&self) -> UIImagePickerControllerQualityType;
418
419 #[unsafe(method(setVideoQuality:))]
421 #[unsafe(method_family = none)]
422 pub fn setVideoQuality(&self, video_quality: UIImagePickerControllerQualityType);
423
424 #[deprecated = "Will be removed in a future release, use PHPicker."]
425 #[unsafe(method(videoExportPreset))]
426 #[unsafe(method_family = none)]
427 pub fn videoExportPreset(&self) -> Retained<NSString>;
428
429 #[deprecated = "Will be removed in a future release, use PHPicker."]
433 #[unsafe(method(setVideoExportPreset:))]
434 #[unsafe(method_family = none)]
435 pub fn setVideoExportPreset(&self, video_export_preset: &NSString);
436
437 #[unsafe(method(showsCameraControls))]
438 #[unsafe(method_family = none)]
439 pub fn showsCameraControls(&self) -> bool;
440
441 #[unsafe(method(setShowsCameraControls:))]
443 #[unsafe(method_family = none)]
444 pub fn setShowsCameraControls(&self, shows_camera_controls: bool);
445
446 #[cfg(feature = "UIView")]
447 #[unsafe(method(cameraOverlayView))]
448 #[unsafe(method_family = none)]
449 pub fn cameraOverlayView(&self) -> Option<Retained<UIView>>;
450
451 #[cfg(feature = "UIView")]
452 #[unsafe(method(setCameraOverlayView:))]
454 #[unsafe(method_family = none)]
455 pub fn setCameraOverlayView(&self, camera_overlay_view: Option<&UIView>);
456
457 #[cfg(feature = "objc2-core-foundation")]
458 #[unsafe(method(cameraViewTransform))]
459 #[unsafe(method_family = none)]
460 pub fn cameraViewTransform(&self) -> CGAffineTransform;
461
462 #[cfg(feature = "objc2-core-foundation")]
463 #[unsafe(method(setCameraViewTransform:))]
465 #[unsafe(method_family = none)]
466 pub fn setCameraViewTransform(&self, camera_view_transform: CGAffineTransform);
467
468 #[unsafe(method(takePicture))]
469 #[unsafe(method_family = none)]
470 pub fn takePicture(&self);
471
472 #[unsafe(method(startVideoCapture))]
473 #[unsafe(method_family = none)]
474 pub fn startVideoCapture(&self) -> bool;
475
476 #[unsafe(method(stopVideoCapture))]
477 #[unsafe(method_family = none)]
478 pub fn stopVideoCapture(&self);
479
480 #[unsafe(method(cameraCaptureMode))]
481 #[unsafe(method_family = none)]
482 pub fn cameraCaptureMode(&self) -> UIImagePickerControllerCameraCaptureMode;
483
484 #[unsafe(method(setCameraCaptureMode:))]
486 #[unsafe(method_family = none)]
487 pub fn setCameraCaptureMode(
488 &self,
489 camera_capture_mode: UIImagePickerControllerCameraCaptureMode,
490 );
491
492 #[unsafe(method(cameraDevice))]
493 #[unsafe(method_family = none)]
494 pub fn cameraDevice(&self) -> UIImagePickerControllerCameraDevice;
495
496 #[unsafe(method(setCameraDevice:))]
498 #[unsafe(method_family = none)]
499 pub fn setCameraDevice(&self, camera_device: UIImagePickerControllerCameraDevice);
500
501 #[unsafe(method(cameraFlashMode))]
502 #[unsafe(method_family = none)]
503 pub fn cameraFlashMode(&self) -> UIImagePickerControllerCameraFlashMode;
504
505 #[unsafe(method(setCameraFlashMode:))]
507 #[unsafe(method_family = none)]
508 pub fn setCameraFlashMode(&self, camera_flash_mode: UIImagePickerControllerCameraFlashMode);
509 );
510}
511
512#[cfg(all(
514 feature = "UINavigationController",
515 feature = "UIResponder",
516 feature = "UIViewController"
517))]
518impl UIImagePickerController {
519 extern_methods!(
520 #[unsafe(method(initWithNavigationBarClass:toolbarClass:))]
525 #[unsafe(method_family = init)]
526 pub unsafe fn initWithNavigationBarClass_toolbarClass(
527 this: Allocated<Self>,
528 navigation_bar_class: Option<&AnyClass>,
529 toolbar_class: Option<&AnyClass>,
530 ) -> Retained<Self>;
531
532 #[unsafe(method(initWithRootViewController:))]
533 #[unsafe(method_family = init)]
534 pub fn initWithRootViewController(
535 this: Allocated<Self>,
536 root_view_controller: &UIViewController,
537 ) -> Retained<Self>;
538
539 #[unsafe(method(initWithNibName:bundle:))]
540 #[unsafe(method_family = init)]
541 pub fn initWithNibName_bundle(
542 this: Allocated<Self>,
543 nib_name_or_nil: Option<&NSString>,
544 nib_bundle_or_nil: Option<&NSBundle>,
545 ) -> Retained<Self>;
546
547 #[unsafe(method(initWithCoder:))]
551 #[unsafe(method_family = init)]
552 pub unsafe fn initWithCoder(
553 this: Allocated<Self>,
554 a_decoder: &NSCoder,
555 ) -> Option<Retained<Self>>;
556 );
557}
558
559#[cfg(all(
561 feature = "UINavigationController",
562 feature = "UIResponder",
563 feature = "UIViewController"
564))]
565impl UIImagePickerController {
566 extern_methods!(
567 #[unsafe(method(init))]
568 #[unsafe(method_family = init)]
569 pub fn init(this: Allocated<Self>) -> Retained<Self>;
570
571 #[unsafe(method(new))]
572 #[unsafe(method_family = new)]
573 pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
574 );
575}
576
577extern_protocol!(
578 pub unsafe trait UIImagePickerControllerDelegate:
580 NSObjectProtocol + MainThreadOnly
581 {
582 #[cfg(all(
583 feature = "UIImage",
584 feature = "UINavigationController",
585 feature = "UIResponder",
586 feature = "UIViewController"
587 ))]
588 #[deprecated]
592 #[optional]
593 #[unsafe(method(imagePickerController:didFinishPickingImage:editingInfo:))]
594 #[unsafe(method_family = none)]
595 unsafe fn imagePickerController_didFinishPickingImage_editingInfo(
596 &self,
597 picker: &UIImagePickerController,
598 image: &UIImage,
599 editing_info: Option<&NSDictionary<UIImagePickerControllerInfoKey, AnyObject>>,
600 );
601
602 #[cfg(all(
603 feature = "UINavigationController",
604 feature = "UIResponder",
605 feature = "UIViewController"
606 ))]
607 #[optional]
611 #[unsafe(method(imagePickerController:didFinishPickingMediaWithInfo:))]
612 #[unsafe(method_family = none)]
613 unsafe fn imagePickerController_didFinishPickingMediaWithInfo(
614 &self,
615 picker: &UIImagePickerController,
616 info: &NSDictionary<UIImagePickerControllerInfoKey, AnyObject>,
617 );
618
619 #[cfg(all(
620 feature = "UINavigationController",
621 feature = "UIResponder",
622 feature = "UIViewController"
623 ))]
624 #[optional]
625 #[unsafe(method(imagePickerControllerDidCancel:))]
626 #[unsafe(method_family = none)]
627 fn imagePickerControllerDidCancel(&self, picker: &UIImagePickerController);
628 }
629);
630
631#[cfg(feature = "UIImage")]
632impl UIImage {
633 #[doc(alias = "UIImageWriteToSavedPhotosAlbum")]
639 #[cfg(feature = "UIImage")]
640 #[inline]
641 pub unsafe fn write_to_saved_photos_album(
642 &self,
643 completion_target: Option<&AnyObject>,
644 completion_selector: Option<Sel>,
645 context_info: *mut c_void,
646 ) {
647 extern "C-unwind" {
648 fn UIImageWriteToSavedPhotosAlbum(
649 image: &UIImage,
650 completion_target: Option<&AnyObject>,
651 completion_selector: Option<Sel>,
652 context_info: *mut c_void,
653 );
654 }
655 unsafe {
656 UIImageWriteToSavedPhotosAlbum(
657 self,
658 completion_target,
659 completion_selector,
660 context_info,
661 )
662 }
663 }
664}
665
666#[inline]
667pub extern "C-unwind" fn UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(
668 video_path: &NSString,
669) -> bool {
670 extern "C-unwind" {
671 fn UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(video_path: &NSString) -> Bool;
672 }
673 unsafe { UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(video_path) }.as_bool()
674}
675
676extern "C-unwind" {
677 pub fn UISaveVideoAtPathToSavedPhotosAlbum(
683 video_path: &NSString,
684 completion_target: Option<&AnyObject>,
685 completion_selector: Option<Sel>,
686 context_info: *mut c_void,
687 );
688}
689
690extern "C-unwind" {
691 #[cfg(feature = "UIImage")]
692 #[deprecated = "renamed to `UIImage::write_to_saved_photos_album`"]
693 pub fn UIImageWriteToSavedPhotosAlbum(
694 image: &UIImage,
695 completion_target: Option<&AnyObject>,
696 completion_selector: Option<Sel>,
697 context_info: *mut c_void,
698 );
699}