Skip to content

Commit e3a9e49

Browse files
refactor: remove code for old Android / iOS versions (#2411)
1 parent 44cbc16 commit e3a9e49

File tree

12 files changed

+126
-221
lines changed

12 files changed

+126
-221
lines changed

camera/README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ with the camera.
143143
pickImages(options: GalleryImageOptions) => Promise<GalleryPhotos>
144144
```
145145

146-
Allows the user to pick multiple pictures from the photo gallery.
147-
On iOS 13 and older it only allows to pick one picture.
146+
Allows the user to pick multiplef pictures from the photo gallery.
148147

149148
| Param | Type |
150149
| ------------- | ------------------------------------------------------------------- |
@@ -163,9 +162,9 @@ On iOS 13 and older it only allows to pick one picture.
163162
pickLimitedLibraryPhotos() => Promise<GalleryPhotos>
164163
```
165164

166-
iOS 14+ Only: Allows the user to update their limited photo library selection.
167-
On iOS 15+ returns all the limited photos after the picker dismissal.
168-
On iOS 14 or if the user gave full access to the photos it returns an empty array.
165+
Allows the user to update their limited photo library selection.
166+
Returns all the limited photos after the picker dismissal.
167+
If instead the user gave full access to the photos it returns an empty array.
169168

170169
**Returns:** <code>Promise&lt;<a href="#galleryphotos">GalleryPhotos</a>&gt;</code>
171170

@@ -180,7 +179,7 @@ On iOS 14 or if the user gave full access to the photos it returns an empty arra
180179
getLimitedLibraryPhotos() => Promise<GalleryPhotos>
181180
```
182181

183-
iOS 14+ Only: Return an array of photos selected from the limited photo library.
182+
Return an array of photos selected from the limited photo library.
184183

185184
**Returns:** <code>Promise&lt;<a href="#galleryphotos">GalleryPhotos</a>&gt;</code>
186185

@@ -244,7 +243,7 @@ Request camera and photo album permissions
244243
| Prop | Type | Description | Default | Since |
245244
| ------------------------ | ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- | ----- |
246245
| **`quality`** | <code>number</code> | The quality of image to return as JPEG, from 0-100 Note: This option is only supported on Android and iOS | | 1.0.0 |
247-
| **`allowEditing`** | <code>boolean</code> | Whether to allow the user to crop or make small edits (platform specific). On iOS 14+ it's only supported for <a href="#camerasource">CameraSource.Camera</a>, but not for <a href="#camerasource">CameraSource.Photos</a>. | | 1.0.0 |
246+
| **`allowEditing`** | <code>boolean</code> | Whether to allow the user to crop or make small edits (platform specific). On iOS it's only supported for <a href="#camerasource">CameraSource.Camera</a>, but not for <a href="#camerasource">CameraSource.Photos</a>. | | 1.0.0 |
248247
| **`resultType`** | <code><a href="#cameraresulttype">CameraResultType</a></code> | How the data should be returned. Currently, only 'Base64', 'DataUrl' or 'Uri' is supported | | 1.0.0 |
249248
| **`saveToGallery`** | <code>boolean</code> | Whether to save the photo to the gallery. If the photo was picked from the gallery, it will only be saved if edited. | <code>: false</code> | 1.0.0 |
250249
| **`width`** | <code>number</code> | The desired maximum width of the saved image. The aspect ratio is respected. | | 1.0.0 |

camera/ios/Sources/CameraPlugin/CameraPlugin.swift

Lines changed: 45 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ public class CameraPlugin: CAPPlugin, CAPBridgedPlugin {
3131
case .camera:
3232
state = AVCaptureDevice.authorizationStatus(for: .video).authorizationState
3333
case .photos:
34-
if #available(iOS 14, *) {
35-
state = PHPhotoLibrary.authorizationStatus(for: .readWrite).authorizationState
36-
} else {
37-
state = PHPhotoLibrary.authorizationStatus().authorizationState
38-
}
34+
state = PHPhotoLibrary.authorizationStatus(for: .readWrite).authorizationState
3935
}
4036
result[permission.rawValue] = state
4137
}
@@ -60,14 +56,8 @@ public class CameraPlugin: CAPPlugin, CAPBridgedPlugin {
6056
}
6157
case .photos:
6258
group.enter()
63-
if #available(iOS 14, *) {
64-
PHPhotoLibrary.requestAuthorization(for: .readWrite) { (_) in
65-
group.leave()
66-
}
67-
} else {
68-
PHPhotoLibrary.requestAuthorization({ (_) in
69-
group.leave()
70-
})
59+
PHPhotoLibrary.requestAuthorization(for: .readWrite) { (_) in
60+
group.leave()
7161
}
7262
}
7363
}
@@ -77,77 +67,62 @@ public class CameraPlugin: CAPPlugin, CAPBridgedPlugin {
7767
}
7868

7969
@objc func pickLimitedLibraryPhotos(_ call: CAPPluginCall) {
80-
if #available(iOS 14, *) {
81-
PHPhotoLibrary.requestAuthorization(for: .readWrite) { (granted) in
82-
if granted == .limited {
83-
if let viewController = self.bridge?.viewController {
84-
if #available(iOS 15, *) {
85-
PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: viewController) { _ in
86-
self.getLimitedLibraryPhotos(call)
87-
}
88-
} else {
89-
PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: viewController)
90-
call.resolve([
91-
"photos": []
92-
])
93-
}
70+
PHPhotoLibrary.requestAuthorization(for: .readWrite) { (granted) in
71+
if granted == .limited {
72+
if let viewController = self.bridge?.viewController {
73+
PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: viewController) { _ in
74+
self.getLimitedLibraryPhotos(call)
9475
}
95-
} else {
96-
call.resolve([
97-
"photos": []
98-
])
9976
}
77+
} else {
78+
call.resolve([
79+
"photos": []
80+
])
10081
}
101-
} else {
102-
call.unavailable("Not available on iOS 13")
10382
}
10483
}
10584

10685
@objc func getLimitedLibraryPhotos(_ call: CAPPluginCall) {
107-
if #available(iOS 14, *) {
108-
PHPhotoLibrary.requestAuthorization(for: .readWrite) { (granted) in
109-
if granted == .limited {
110-
111-
self.call = call
112-
113-
DispatchQueue.global(qos: .utility).async {
114-
let assets = PHAsset.fetchAssets(with: .image, options: nil)
115-
var processedImages: [ProcessedImage] = []
116-
117-
let imageManager = PHImageManager.default()
118-
let options = PHImageRequestOptions()
119-
options.deliveryMode = .highQualityFormat
120-
121-
let group = DispatchGroup()
122-
if assets.count > 0 {
123-
for index in 0...(assets.count - 1) {
124-
let asset = assets.object(at: index)
125-
let fullSize = CGSize(width: asset.pixelWidth, height: asset.pixelHeight)
126-
127-
group.enter()
128-
imageManager.requestImage(for: asset, targetSize: fullSize, contentMode: .default, options: options) { image, _ in
129-
guard let image = image else {
130-
group.leave()
131-
return
132-
}
133-
processedImages.append(self.processedImage(from: image, with: asset.imageData))
86+
PHPhotoLibrary.requestAuthorization(for: .readWrite) { (granted) in
87+
if granted == .limited {
88+
89+
self.call = call
90+
91+
DispatchQueue.global(qos: .utility).async {
92+
let assets = PHAsset.fetchAssets(with: .image, options: nil)
93+
var processedImages: [ProcessedImage] = []
94+
95+
let imageManager = PHImageManager.default()
96+
let options = PHImageRequestOptions()
97+
options.deliveryMode = .highQualityFormat
98+
99+
let group = DispatchGroup()
100+
if assets.count > 0 {
101+
for index in 0...(assets.count - 1) {
102+
let asset = assets.object(at: index)
103+
let fullSize = CGSize(width: asset.pixelWidth, height: asset.pixelHeight)
104+
105+
group.enter()
106+
imageManager.requestImage(for: asset, targetSize: fullSize, contentMode: .default, options: options) { image, _ in
107+
guard let image = image else {
134108
group.leave()
109+
return
135110
}
111+
processedImages.append(self.processedImage(from: image, with: asset.imageData))
112+
group.leave()
136113
}
137114
}
115+
}
138116

139-
group.notify(queue: .global(qos: .utility)) { [weak self] in
140-
self?.returnImages(processedImages)
141-
}
117+
group.notify(queue: .global(qos: .utility)) { [weak self] in
118+
self?.returnImages(processedImages)
142119
}
143-
} else {
144-
call.resolve([
145-
"photos": []
146-
])
147120
}
121+
} else {
122+
call.resolve([
123+
"photos": []
124+
])
148125
}
149-
} else {
150-
call.unavailable("Not available on iOS 13")
151126
}
152127
}
153128

@@ -252,7 +227,6 @@ extension CameraPlugin: UIImagePickerControllerDelegate, UINavigationControllerD
252227
}
253228
}
254229

255-
@available(iOS 14, *)
256230
extension CameraPlugin: PHPickerViewControllerDelegate {
257231
public func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
258232
picker.dismiss(animated: true, completion: nil)
@@ -490,11 +464,7 @@ private extension CameraPlugin {
490464
}
491465

492466
func presentSystemAppropriateImagePicker() {
493-
if #available(iOS 14, *) {
494-
presentPhotoPicker()
495-
} else {
496-
presentImagePicker()
497-
}
467+
presentPhotoPicker()
498468
}
499469

500470
func presentImagePicker() {
@@ -512,7 +482,6 @@ private extension CameraPlugin {
512482
bridge?.viewController?.present(picker, animated: true, completion: nil)
513483
}
514484

515-
@available(iOS 14, *)
516485
func presentPhotoPicker() {
517486
var configuration = PHPickerConfiguration(photoLibrary: PHPhotoLibrary.shared())
518487
configuration.selectionLimit = self.multiple ? (self.call?.getInt("limit") ?? 0) : 1

camera/src/definitions.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,22 @@ export interface CameraPlugin {
2323
getPhoto(options: ImageOptions): Promise<Photo>;
2424

2525
/**
26-
* Allows the user to pick multiple pictures from the photo gallery.
27-
* On iOS 13 and older it only allows to pick one picture.
26+
* Allows the user to pick multiplef pictures from the photo gallery.
2827
*
2928
* @since 1.2.0
3029
*/
3130
pickImages(options: GalleryImageOptions): Promise<GalleryPhotos>;
3231

3332
/**
34-
* iOS 14+ Only: Allows the user to update their limited photo library selection.
35-
* On iOS 15+ returns all the limited photos after the picker dismissal.
36-
* On iOS 14 or if the user gave full access to the photos it returns an empty array.
33+
* Allows the user to update their limited photo library selection.
34+
* Returns all the limited photos after the picker dismissal.
35+
* If instead the user gave full access to the photos it returns an empty array.
3736
*
3837
* @since 4.1.0
3938
*/
4039
pickLimitedLibraryPhotos(): Promise<GalleryPhotos>;
4140
/**
42-
* iOS 14+ Only: Return an array of photos selected from the limited photo library.
41+
* Return an array of photos selected from the limited photo library.
4342
*
4443
* @since 4.1.0
4544
*/
@@ -72,7 +71,7 @@ export interface ImageOptions {
7271
quality?: number;
7372
/**
7473
* Whether to allow the user to crop or make small edits (platform specific).
75-
* On iOS 14+ it's only supported for CameraSource.Camera, but not for CameraSource.Photos.
74+
* On iOS it's only supported for CameraSource.Camera, but not for CameraSource.Photos.
7675
*
7776
* @since 1.0.0
7877
*/

device/android/src/main/java/com/capacitorjs/plugins/device/Device.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,8 @@ public String getWebViewVersion() {
8888
return android.os.Build.VERSION.RELEASE;
8989
}
9090

91-
@SuppressWarnings("deprecation")
9291
private PackageInfo getWebViewVersionSubAndroid26() throws PackageManager.NameNotFoundException {
93-
String webViewPackage = "com.google.android.webview";
94-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
95-
webViewPackage = "com.android.chrome";
96-
}
9792
PackageManager pm = this.context.getPackageManager();
98-
return pm.getPackageInfo(webViewPackage, 0);
93+
return pm.getPackageInfo("com.android.chrome", 0);
9994
}
10095
}

keyboard/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,11 @@ Remove all native listeners for this plugin.
372372

373373
#### KeyboardStyle
374374

375-
| Members | Value | Description | Since |
376-
| ------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
377-
| **`Dark`** | <code>'DARK'</code> | Dark keyboard. | 1.0.0 |
378-
| **`Light`** | <code>'LIGHT'</code> | Light keyboard. | 1.0.0 |
379-
| **`Default`** | <code>'DEFAULT'</code> | On iOS 13 and newer the keyboard style is based on the device appearance. If the device is using Dark mode, the keyboard will be dark. If the device is using Light mode, the keyboard will be light. On iOS 12 the keyboard will be light. | 1.0.0 |
375+
| Members | Value | Description | Since |
376+
| ------------- | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
377+
| **`Dark`** | <code>'DARK'</code> | Dark keyboard. | 1.0.0 |
378+
| **`Light`** | <code>'LIGHT'</code> | Light keyboard. | 1.0.0 |
379+
| **`Default`** | <code>'DEFAULT'</code> | The keyboard style is based on the device appearance. If the device is using Dark mode, the keyboard will be dark. If the device is using Light mode, the keyboard will be light. | 1.0.0 |
380380

381381

382382
#### KeyboardResize

keyboard/src/definitions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,9 @@ export enum KeyboardStyle {
8080
Light = 'LIGHT',
8181

8282
/**
83-
* On iOS 13 and newer the keyboard style is based on the device appearance.
83+
* The keyboard style is based on the device appearance.
8484
* If the device is using Dark mode, the keyboard will be dark.
8585
* If the device is using Light mode, the keyboard will be light.
86-
* On iOS 12 the keyboard will be light.
8786
*
8887
* @since 1.0.0
8988
*/

0 commit comments

Comments
 (0)