Skip to content

Replacing all instances of [UIApplication sharedApplication] wi… #13227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Libraries/PushNotificationIOS/RCTPushNotificationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ - (void)stopObserving
+ (void)didRegisterUserNotificationSettings:(__unused UIUserNotificationSettings *)notificationSettings
{
if ([UIApplication instancesRespondToSelector:@selector(registerForRemoteNotifications)]) {
[[UIApplication sharedApplication] registerForRemoteNotifications];
[RCTSharedApplication() registerForRemoteNotifications];
[[NSNotificationCenter defaultCenter] postNotificationName:RCTRegisterUserNotificationSettings
object:self
userInfo:@{@"notificationSettings": notificationSettings}];
Expand Down Expand Up @@ -378,7 +378,7 @@ - (void)handleRegisterUserNotificationSettings:(NSNotification *)notification

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:`
Expand All @@ -392,7 +392,7 @@ - (void)handleRegisterUserNotificationSettings:(NSNotification *)notification
}
}];
if (matchesAll) {
[[UIApplication sharedApplication] cancelLocalNotification:notification];
[RCTSharedApplication() cancelLocalNotification:notification];
}
}
}
Expand All @@ -418,7 +418,7 @@ - (void)handleRegisterUserNotificationSettings:(NSNotification *)notification

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)];
Expand Down
2 changes: 1 addition & 1 deletion Libraries/RCTTest/RCTTestRunner.m
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ - (void)runTest:(SEL)test module:(NSString *)moduleName
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

Expand Down
1 change: 1 addition & 0 deletions React/Base/RCTLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#import <React/RCTAssert.h>
#import <React/RCTDefines.h>
#import <React/RCTUtils.h>

#ifndef RCTLOG_ENABLED
#define RCTLOG_ENABLED 1
Expand Down
2 changes: 1 addition & 1 deletion React/Base/RCTLog.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down
4 changes: 2 additions & 2 deletions React/Modules/RCTAccessibilityManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ - (instancetype)init
[[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;
Expand Down
2 changes: 1 addition & 1 deletion React/Modules/RCTStatusBarManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ - (void)applicationWillChangeStatusBarFrame:(NSNotification *)notification
RCT_EXPORT_METHOD(getHeight:(RCTResponseSenderBlock)callback)
{
callback(@[@{
@"height": @([UIApplication sharedApplication].statusBarFrame.size.height),
@"height": @(RCTSharedApplication().statusBarFrame.size.height),
}]);
}

Expand Down
3 changes: 2 additions & 1 deletion React/Profiler/RCTPerfMonitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -321,7 +322,7 @@ - (void)show

[self updateStats];

UIWindow *window = [UIApplication sharedApplication].delegate.window;
UIWindow *window = RCTSharedApplication().delegate.window;
[window addSubview:self.container];


Expand Down
2 changes: 1 addition & 1 deletion React/Profiler/RCTProfile.m
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ + (void)toggle:(UIButton *)target
};
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];
});
Expand Down
3 changes: 2 additions & 1 deletion React/Views/RCTModalHostView.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#import "RCTModalHostViewController.h"
#import "RCTTouchHandler.h"
#import "RCTUIManager.h"
#import "RCTUtils.h"
#import "UIView+React.h"

@implementation RCTModalHostView
Expand Down Expand Up @@ -68,7 +69,7 @@ - (void)notifyForOrientationChange
return;
}

UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
UIInterfaceOrientation currentOrientation = [RCTSharedApplication() statusBarOrientation];
if (currentOrientation == _lastKnownOrientation) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions React/Views/RCTModalHostViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ - (instancetype)init
}

#if !TARGET_OS_TV
_preferredStatusBarStyle = [[UIApplication sharedApplication] statusBarStyle];
_preferredStatusBarHidden = [[UIApplication sharedApplication] isStatusBarHidden];
_preferredStatusBarStyle = [RCTSharedApplication() statusBarStyle];
_preferredStatusBarHidden = [RCTSharedApplication() isStatusBarHidden];
#endif

return self;
Expand Down Expand Up @@ -59,7 +59,7 @@ - (BOOL)prefersStatusBarHidden
#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."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test

- (void)testRendersWelcomeScreen
{
UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
BOOL foundElement = NO;

Expand Down