Replacing all instances of [UIApplication sharedApplication] wi…
Summary: …th RCTSharedApplication() Thanks for submitting a PR! Please read these instructions carefully: - [ ] Explain the **motivation** for making this change. Using React Native latest version with Cocoapods 1.2.0 causes the following error inside iOS app extensions > /react-native/React/Modules/RCTAccessibilityManager.m:67:70: ‘sharedApplication’ is unavailable: not available on iOS (App Extension) — Use view controller based solutions where appropriate instead. Moving the use of [UIApplication sharedApplication] to RCTSharedApplication() which is safe on app extension - [ ] Provide a **test plan** demonstrating that the code is solid. I am not sure how to test such that all the features which touch the modified code are tested. - [ ] Match the **code formatting** of the rest of the codebase. - [ ] Target the `master` branch, NOT a "stable" branch. What existing problem does the pull request solve? Using React Native latest v Closes https://github.com/facebook/react-native/pull/13227 Differential Revision: D4816338 Pulled By: javache fbshipit-source-id: e3e3c77882990ad1817b0b633521cff52571ecd0
This commit is contained in:
parent
7ff18f290b
commit
edbb48c67a
|
@ -172,7 +172,7 @@ RCT_EXPORT_MODULE()
|
|||
+ (void)didRegisterUserNotificationSettings:(__unused UIUserNotificationSettings *)notificationSettings
|
||||
{
|
||||
if ([UIApplication instancesRespondToSelector:@selector(registerForRemoteNotifications)]) {
|
||||
[[UIApplication sharedApplication] registerForRemoteNotifications];
|
||||
[RCTSharedApplication() registerForRemoteNotifications];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RCTRegisterUserNotificationSettings
|
||||
object:self
|
||||
userInfo:@{@"notificationSettings": notificationSettings}];
|
||||
|
@ -378,7 +378,7 @@ RCT_EXPORT_METHOD(cancelAllLocalNotifications)
|
|||
|
||||
RCT_EXPORT_METHOD(cancelLocalNotifications:(NSDictionary<NSString *, id> *)userInfo)
|
||||
{
|
||||
for (UILocalNotification *notification in [UIApplication sharedApplication].scheduledLocalNotifications) {
|
||||
for (UILocalNotification *notification in RCTSharedApplication().scheduledLocalNotifications) {
|
||||
__block BOOL matchesAll = YES;
|
||||
NSDictionary<NSString *, id> *notificationInfo = notification.userInfo;
|
||||
// Note: we do this with a loop instead of just `isEqualToDictionary:`
|
||||
|
@ -392,7 +392,7 @@ RCT_EXPORT_METHOD(cancelLocalNotifications:(NSDictionary<NSString *, id> *)userI
|
|||
}
|
||||
}];
|
||||
if (matchesAll) {
|
||||
[[UIApplication sharedApplication] cancelLocalNotification:notification];
|
||||
[RCTSharedApplication() cancelLocalNotification:notification];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -418,7 +418,7 @@ RCT_EXPORT_METHOD(getInitialNotification:(RCTPromiseResolveBlock)resolve
|
|||
|
||||
RCT_EXPORT_METHOD(getScheduledLocalNotifications:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
NSArray<UILocalNotification *> *scheduledLocalNotifications = [UIApplication sharedApplication].scheduledLocalNotifications;
|
||||
NSArray<UILocalNotification *> *scheduledLocalNotifications = RCTSharedApplication().scheduledLocalNotifications;
|
||||
NSMutableArray<NSDictionary *> *formattedScheduledLocalNotifications = [NSMutableArray new];
|
||||
for (UILocalNotification *notification in scheduledLocalNotifications) {
|
||||
[formattedScheduledLocalNotifications addObject:RCTFormatLocalNotification(notification)];
|
||||
|
|
|
@ -121,7 +121,7 @@ expectErrorBlock:(BOOL(^)(NSString *error))expectErrorBlock
|
|||
testModule.testSuffix = _testSuffix;
|
||||
testModule.view = rootView;
|
||||
|
||||
UIViewController *vc = [UIApplication sharedApplication].delegate.window.rootViewController;
|
||||
UIViewController *vc = RCTSharedApplication().delegate.window.rootViewController;
|
||||
vc.view = [UIView new];
|
||||
[vc.view addSubview:rootView]; // Add as subview so it doesn't get resized
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#import <React/RCTAssert.h>
|
||||
#import <React/RCTDefines.h>
|
||||
#import <React/RCTUtils.h>
|
||||
|
||||
#ifndef RCTLOG_ENABLED
|
||||
#define RCTLOG_ENABLED 1
|
||||
|
|
|
@ -218,7 +218,7 @@ void _RCTLogNativeInternal(RCTLogLevel level, const char *fileName, int lineNumb
|
|||
#if RCT_DEBUG
|
||||
|
||||
// Log to red box in debug mode.
|
||||
if ([UIApplication sharedApplication] && level >= RCTLOG_REDBOX_LEVEL) {
|
||||
if (RCTSharedApplication() && level >= RCTLOG_REDBOX_LEVEL) {
|
||||
NSArray<NSString *> *stackSymbols = [NSThread callStackSymbols];
|
||||
NSMutableArray<NSDictionary *> *stack =
|
||||
[NSMutableArray arrayWithCapacity:(stackSymbols.count - 1)];
|
||||
|
|
|
@ -64,14 +64,14 @@ RCT_EXPORT_MODULE()
|
|||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(didReceiveNewContentSizeCategory:)
|
||||
name:UIContentSizeCategoryDidChangeNotification
|
||||
object:[UIApplication sharedApplication]];
|
||||
object:RCTSharedApplication()];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(didReceiveNewVoiceOverStatus:)
|
||||
name:UIAccessibilityVoiceOverStatusChanged
|
||||
object:nil];
|
||||
|
||||
self.contentSizeCategory = [UIApplication sharedApplication].preferredContentSizeCategory;
|
||||
self.contentSizeCategory = RCTSharedApplication().preferredContentSizeCategory;
|
||||
_isVoiceOverEnabled = UIAccessibilityIsVoiceOverRunning();
|
||||
}
|
||||
return self;
|
||||
|
|
|
@ -99,7 +99,7 @@ RCT_EXPORT_MODULE()
|
|||
RCT_EXPORT_METHOD(getHeight:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
callback(@[@{
|
||||
@"height": @([UIApplication sharedApplication].statusBarFrame.size.height),
|
||||
@"height": @(RCTSharedApplication().statusBarFrame.size.height),
|
||||
}]);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#import "RCTRootView.h"
|
||||
#import "RCTUIManager.h"
|
||||
#import "RCTBridge+Private.h"
|
||||
#import "RCTUtils.h"
|
||||
|
||||
#if __has_include("RCTDevMenu.h")
|
||||
#import "RCTDevMenu.h"
|
||||
|
@ -321,7 +322,7 @@ RCT_EXPORT_MODULE()
|
|||
|
||||
[self updateStats];
|
||||
|
||||
UIWindow *window = [UIApplication sharedApplication].delegate.window;
|
||||
UIWindow *window = RCTSharedApplication().delegate.window;
|
||||
[window addSubview:self.container];
|
||||
|
||||
|
||||
|
|
|
@ -404,7 +404,7 @@ void RCTProfileUnhookModules(RCTBridge *bridge)
|
|||
};
|
||||
RCTProfileControlsWindow.hidden = YES;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:activityViewController
|
||||
[[[[RCTSharedApplication() delegate] window] rootViewController] presentViewController:activityViewController
|
||||
animated:YES
|
||||
completion:nil];
|
||||
});
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#import "RCTModalHostViewController.h"
|
||||
#import "RCTTouchHandler.h"
|
||||
#import "RCTUIManager.h"
|
||||
#import "RCTUtils.h"
|
||||
#import "UIView+React.h"
|
||||
|
||||
@implementation RCTModalHostView
|
||||
|
@ -68,7 +69,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:coder)
|
|||
return;
|
||||
}
|
||||
|
||||
UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
|
||||
UIInterfaceOrientation currentOrientation = [RCTSharedApplication() statusBarOrientation];
|
||||
if (currentOrientation == _lastKnownOrientation) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
}
|
||||
|
||||
#if !TARGET_OS_TV
|
||||
_preferredStatusBarStyle = [[UIApplication sharedApplication] statusBarStyle];
|
||||
_preferredStatusBarHidden = [[UIApplication sharedApplication] isStatusBarHidden];
|
||||
_preferredStatusBarStyle = [RCTSharedApplication() statusBarStyle];
|
||||
_preferredStatusBarHidden = [RCTSharedApplication() isStatusBarHidden];
|
||||
#endif
|
||||
|
||||
return self;
|
||||
|
@ -59,7 +59,7 @@
|
|||
#if RCT_DEV
|
||||
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
|
||||
{
|
||||
UIInterfaceOrientationMask appSupportedOrientationsMask = [[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:[[UIApplication sharedApplication] keyWindow]];
|
||||
UIInterfaceOrientationMask appSupportedOrientationsMask = [RCTSharedApplication() supportedInterfaceOrientationsForWindow:[RCTSharedApplication() keyWindow]];
|
||||
if (!(_supportedInterfaceOrientations & appSupportedOrientationsMask)) {
|
||||
RCTLogError(@"Modal was presented with 0x%x orientations mask but the application only supports 0x%x."
|
||||
@"Add more interface orientations to your app's Info.plist to fix this."
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
- (void)testRendersWelcomeScreen
|
||||
{
|
||||
UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
|
||||
UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];
|
||||
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
|
||||
BOOL foundElement = NO;
|
||||
|
||||
|
|
Loading…
Reference in New Issue