Skip to content

Commit a958597

Browse files
authored
Silences unguarded availability warnings in Auth. (#389)
Also fixes a crash in the Auth sample app in an error case. This addresses *Auth* part of #385 .
1 parent 024788e commit a958597

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

Example/Auth/Sample/MainViewController.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2537,7 +2537,9 @@ - (void)signInWithPhoneNumber:(NSString *_Nullable)phoneNumber
25372537
if (error) {
25382538
[self logFailure:@"failed to send verification code" error:error];
25392539
[self showMessagePrompt:error.localizedDescription];
2540-
completion(error);
2540+
if (completion) {
2541+
completion(error);
2542+
}
25412543
return;
25422544
}
25432545
[self logSuccess:@"Code sent"];

Firebase/Auth/Source/FIRAuthAppDelegateProxy.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ static id noop(id object, SEL cmd, ...) {
4040
}
4141
#endif
4242

43+
/** @fn isIOS9orLater
44+
@brief Checks whether the iOS version is 9 or later.
45+
@returns Whether the iOS version is 9 or later.
46+
*/
47+
static BOOL isIOS9orLater() {
48+
#if defined(__IPHONE_11_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0)
49+
if (@available(iOS 9.0, *)) {
50+
return YES;
51+
}
52+
return NO;
53+
#else
54+
return &UIApplicationOpenURLOptionsAnnotationKey; // the constant is only available on iOS 9+
55+
#endif
56+
}
57+
4358
@implementation FIRAuthAppDelegateProxy {
4459
/** @var _appDelegate
4560
@brief The application delegate whose method is being swizzled.
@@ -119,7 +134,7 @@ - (nullable instancetype)initWithApplication:(nullable UIApplication *)applicati
119134
SEL openURLOptionsSelector = @selector(application:openURL:options:);
120135
SEL openURLAnnotationSelector = @selector(application:openURL:sourceApplication:annotation:);
121136
SEL handleOpenURLSelector = @selector(application:handleOpenURL:);
122-
if (&UIApplicationOpenURLOptionsAnnotationKey && // the constant is only available on iOS 9+
137+
if (isIOS9orLater() &&
123138
([_appDelegate respondsToSelector:openURLOptionsSelector] ||
124139
(![_appDelegate respondsToSelector:openURLAnnotationSelector] &&
125140
![_appDelegate respondsToSelector:handleOpenURLSelector]))) {

Firebase/Auth/Source/FIRAuthURLPresenter.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ @interface FIRAuthURLPresenter () <SFSafariViewControllerDelegate,
3030
FIRAuthWebViewControllerDelegate>
3131
@end
3232

33+
// Disable unguarded availability warnings because SFSafariViewController is been used throughout
34+
// the code, including as an iVar, which cannot be simply excluded by @available check.
35+
#pragma clang diagnostic push
36+
#pragma clang diagnostic ignored "-Wunguarded-availability"
37+
3338
@implementation FIRAuthURLPresenter {
3439
/** @var _isPresenting
3540
@brief Whether or not some web-based content is being presented.
@@ -176,6 +181,8 @@ - (void)finishPresentationWithURL:(nullable NSURL *)URL
176181
}
177182
}
178183

184+
#pragma clang diagnostic pop // ignored "-Wunguarded-availability"
185+
179186
@end
180187

181188
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)