Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit b7cc93b

Browse files
benbfacebook-github-bot
authored andcommitted
flipper | availability checks for catalyst
Summary: Needed to allow compilation for catalyst when min version < 14 Differential Revision: D57328418 fbshipit-source-id: 0b3b120c83d9d92440828a0d522cac72a35aa4a4
1 parent 31af024 commit b7cc93b

5 files changed

+87
-67
lines changed

iOS/FlipperKit/FlipperClient.mm

+4-1
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,11 @@ - (instancetype)init {
127127
}
128128

129129
#if !TARGET_OS_OSX
130-
[self setBackupCertificateProvider:[[FlipperKitQRVerifiedCertificateProvider
130+
if (@available(macCatalyst 14.0, *)) {
131+
[self
132+
setBackupCertificateProvider:[[FlipperKitQRVerifiedCertificateProvider
131133
alloc] initCPPCertificateProvider]];
134+
}
132135
#endif
133136
}
134137
return self;

iOS/FlipperKit/FlipperKitQRReader.h

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef void (^FBFlipperKitQRResult)(
3030
/** QRReader controller that displays the camera and attempts to read QR
3131
* metadata objects.
3232
*/
33+
API_AVAILABLE(macCatalyst(14.0))
3334
@interface FBFlipperKitQRReaderController : UIViewController
3435

3536
- (instancetype _Nonnull)initWith:(FBFlipperKitQRResult _Nonnull)completion;
@@ -39,6 +40,7 @@ typedef void (^FBFlipperKitQRResult)(
3940
/** QRReader prompt. Shows an alert to the user asking to scan a QR with the
4041
* device's camera.
4142
*/
43+
API_AVAILABLE(macCatalyst(14.0))
4244
@interface FBFlipperKitQRReaderPrompt : UIAlertController
4345

4446
- (void)show;
@@ -50,6 +52,7 @@ typedef void (^FBFlipperKitQRResult)(
5052

5153
/** QRReader entrypoint.
5254
*/
55+
API_AVAILABLE(macCatalyst(14.0))
5356
@interface FlipperKitQRReader : NSObject
5457

5558
+ (void)read:(FBFlipperKitQRResult _Nonnull)result;

iOS/FlipperKit/FlipperKitQRReader.mm

+6-2
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,16 @@ @interface FBFlipperKitQRReaderController ()<
8484

8585
@property(atomic) BOOL isReading;
8686
@property(nonatomic, strong) UIWindow* promptWindow;
87-
@property(nonatomic, strong) AVCaptureSession* captureSession;
88-
@property(nonatomic, strong) AVCaptureVideoPreviewLayer* videoPreviewPlayer;
87+
@property(nonatomic, strong)
88+
AVCaptureSession* captureSession API_AVAILABLE(macCatalyst(14.0));
89+
@property(nonatomic, strong)
90+
AVCaptureVideoPreviewLayer* videoPreviewPlayer API_AVAILABLE(
91+
macCatalyst(14.0));
8992
@property(nonatomic, strong) AVAudioPlayer* audioPlayer;
9093

9194
@end
9295

96+
API_AVAILABLE(macCatalyst(14.0))
9397
@implementation FBFlipperKitQRReaderController
9498

9599
+ (void)readQRWith:(FBFlipperKitQRResult)completion {

iOS/FlipperKit/FlipperKitQRVerifiedCertificateProvider.h

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class QRVerifiedCertificateProvider : public FlipperCertificateProvider {
4444
} // namespace flipper
4545
} // namespace facebook
4646

47+
API_AVAILABLE(macCatalyst(14.0))
4748
@interface FlipperKitQRVerifiedCertificateProvider
4849
: NSObject<FlipperKitCertificateProvider>
4950

iOS/FlipperKit/FlipperKitQRVerifiedCertificateProvider.mm

+73-64
Original file line numberDiff line numberDiff line change
@@ -79,72 +79,81 @@
7979
: nullptr;
8080

8181
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
82-
[FlipperKitQRReader read:^(
83-
NSString* key,
84-
NSError* error,
85-
BOOL cancelled,
86-
FBFlipperKitQRResultAck readResultAck) {
87-
if (error || cancelled) {
88-
// If the QR code was cancelled, we should not proceed on further
89-
// requests.
90-
cancelled_ = cancelled;
91-
certError =
92-
[NSError errorWithDomain:FBFlipperKitQRCertificateProviderErrorDomain
93-
code:-1
94-
userInfo:@{
95-
NSLocalizedDescriptionKey : NSLocalizedString(
96-
@"Unable to read key from QR code", nil),
97-
}];
82+
if (@available(macCatalyst 14.0, *)) {
83+
[FlipperKitQRReader read:^(
84+
NSString* key,
85+
NSError* error,
86+
BOOL cancelled,
87+
FBFlipperKitQRResultAck readResultAck) {
88+
if (error || cancelled) {
89+
// If the QR code was cancelled, we should not proceed on further
90+
// requests.
91+
cancelled_ = cancelled;
92+
certError = [NSError
93+
errorWithDomain:FBFlipperKitQRCertificateProviderErrorDomain
94+
code:-1
95+
userInfo:@{
96+
NSLocalizedDescriptionKey : NSLocalizedString(
97+
@"Unable to read key from QR code", nil),
98+
}];
99+
dispatch_semaphore_signal(semaphore);
100+
return;
101+
}
102+
103+
// Get the data from the base64-encoded key.
104+
NSData* keyData = [[NSData alloc] initWithBase64EncodedString:key
105+
options:0];
106+
// QR codes may be corrupt, invalid, or just contain a different
107+
// content to the one that is expected i.e. base-64 encoded key.
108+
// If that is the case, then just return with an error.
109+
if (!keyData) {
110+
readResultAck(QRReaderResultError);
111+
return;
112+
}
113+
114+
auto success = AESDecrypt(
115+
[encryptedCertificatesPath UTF8String],
116+
[certificatesPath UTF8String],
117+
(const unsigned char*)[keyData bytes]);
118+
119+
// If the decryption failed, must likely, the key is invalid which may be
120+
// caused by an erroneous QR read.
121+
if (!success) {
122+
readResultAck(QRReaderResultError);
123+
return;
124+
}
125+
126+
// If the decryption was successful, we can now read the certificates.
127+
// The certificates are stored in a zip file. Unzip to destination.
128+
129+
[SSZipArchive unzipFileAtPath:certificatesPath toDestination:destination];
130+
131+
// Remove the certificate zip file.
132+
[fileManager removeItemAtPath:certificatesPath error:nil];
133+
134+
// At this stage, dismiss the QR code reader.
135+
readResultAck(QRReaderResultAccepted);
136+
137+
if (QRReadStep) {
138+
QRReadStep->complete();
139+
}
140+
141+
// Signal the semaphore as to unblock the connection thread.
98142
dispatch_semaphore_signal(semaphore);
99143
return;
100-
}
101-
102-
// Get the data from the base64-encoded key.
103-
NSData* keyData = [[NSData alloc] initWithBase64EncodedString:key
104-
options:0];
105-
// QR codes may be corrupt, invalid, or just contain a different
106-
// content to the one that is expected i.e. base-64 encoded key.
107-
// If that is the case, then just return with an error.
108-
if (!keyData) {
109-
readResultAck(QRReaderResultError);
110-
return;
111-
}
112-
113-
auto success = AESDecrypt(
114-
[encryptedCertificatesPath UTF8String],
115-
[certificatesPath UTF8String],
116-
(const unsigned char*)[keyData bytes]);
117-
118-
// If the decryption failed, must likely, the key is invalid which may be
119-
// caused by an erroneous QR read.
120-
if (!success) {
121-
readResultAck(QRReaderResultError);
122-
return;
123-
}
124-
125-
// If the decryption was successful, we can now read the certificates.
126-
// The certificates are stored in a zip file. Unzip to destination.
127-
128-
[SSZipArchive unzipFileAtPath:certificatesPath toDestination:destination];
129-
130-
// Remove the certificate zip file.
131-
[fileManager removeItemAtPath:certificatesPath error:nil];
132-
133-
// At this stage, dismiss the QR code reader.
134-
readResultAck(QRReaderResultAccepted);
135-
136-
if (QRReadStep) {
137-
QRReadStep->complete();
138-
}
139-
140-
// Signal the semaphore as to unblock the connection thread.
141-
dispatch_semaphore_signal(semaphore);
142-
return;
143-
}];
144-
145-
// Wait for the semaphore to be signalled. This will block the connection
146-
// thread until the QR code is read or an error takes place.
147-
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
144+
}];
145+
// Wait for the semaphore to be signalled. This will block the connection
146+
// thread until the QR code is read or an error takes place.
147+
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
148+
} else {
149+
certError = [NSError
150+
errorWithDomain:FBFlipperKitQRCertificateProviderErrorDomain
151+
code:-1
152+
userInfo:@{
153+
NSLocalizedDescriptionKey : NSLocalizedString(
154+
@"Unsupported platform for QR Certificate Provider", nil),
155+
}];
156+
}
148157

149158
// Remove the encrypted certificates.
150159
[fileManager removeItemAtPath:encryptedCertificatesPath error:nil];

0 commit comments

Comments
 (0)