Browse Source

Revert "Use UIStoryboard methods for presenting a splash screen on iOS (#1453)" (#1457)

This reverts commit 36d2c7e35c.
Daniel Zlotin 7 years ago
parent
commit
2666cb1644
1 changed files with 27 additions and 15 deletions
  1. 27
    15
      ios/RCCManager.m

+ 27
- 15
ios/RCCManager.m View File

134
 -(void)showSplashScreen
134
 -(void)showSplashScreen
135
 {
135
 {
136
   CGRect screenBounds = [UIScreen mainScreen].bounds;
136
   CGRect screenBounds = [UIScreen mainScreen].bounds;
137
-  UIViewController *splashViewController = nil;
138
-
137
+  UIView *splashView = nil;
138
+  
139
   NSString* launchStoryBoard = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
139
   NSString* launchStoryBoard = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
140
   if (launchStoryBoard != nil)
140
   if (launchStoryBoard != nil)
141
   {//load the splash from the storyboard that's defined in the info.plist as the LaunchScreen
141
   {//load the splash from the storyboard that's defined in the info.plist as the LaunchScreen
142
-    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:launchStoryBoard bundle:[NSBundle mainBundle]];
143
-    splashViewController = [storyboard instantiateInitialViewController];
142
+    @try
143
+    {
144
+      splashView = [[NSBundle mainBundle] loadNibNamed:launchStoryBoard owner:self options:nil][0];
145
+      if (splashView != nil)
146
+      {
147
+        splashView.frame = CGRectMake(0, 0, screenBounds.size.width, screenBounds.size.height);
148
+      }
149
+    }
150
+    @catch(NSException *e)
151
+    {
152
+      splashView = nil;
153
+    }
144
   }
154
   }
145
   else
155
   else
146
   {//load the splash from the DEfault image or from LaunchImage in the xcassets
156
   {//load the splash from the DEfault image or from LaunchImage in the xcassets
147
     CGFloat screenHeight = screenBounds.size.height;
157
     CGFloat screenHeight = screenBounds.size.height;
148
-
158
+    
149
     NSString* imageName = @"Default";
159
     NSString* imageName = @"Default";
150
     if (screenHeight == 568)
160
     if (screenHeight == 568)
151
       imageName = [imageName stringByAppendingString:@"-568h"];
161
       imageName = [imageName stringByAppendingString:@"-568h"];
153
       imageName = [imageName stringByAppendingString:@"-667h"];
163
       imageName = [imageName stringByAppendingString:@"-667h"];
154
     else if (screenHeight == 736)
164
     else if (screenHeight == 736)
155
       imageName = [imageName stringByAppendingString:@"-736h"];
165
       imageName = [imageName stringByAppendingString:@"-736h"];
156
-
166
+    
157
     //xcassets LaunchImage files
167
     //xcassets LaunchImage files
158
     UIImage *image = [UIImage imageNamed:imageName];
168
     UIImage *image = [UIImage imageNamed:imageName];
159
     if (image == nil)
169
     if (image == nil)
160
     {
170
     {
161
       imageName = @"LaunchImage";
171
       imageName = @"LaunchImage";
162
-
172
+      
163
       if (screenHeight == 480)
173
       if (screenHeight == 480)
164
         imageName = [imageName stringByAppendingString:@"-700"];
174
         imageName = [imageName stringByAppendingString:@"-700"];
165
       if (screenHeight == 568)
175
       if (screenHeight == 568)
168
         imageName = [imageName stringByAppendingString:@"-800-667h"];
178
         imageName = [imageName stringByAppendingString:@"-800-667h"];
169
       else if (screenHeight == 736)
179
       else if (screenHeight == 736)
170
         imageName = [imageName stringByAppendingString:@"-800-Portrait-736h"];
180
         imageName = [imageName stringByAppendingString:@"-800-Portrait-736h"];
171
-
181
+      
172
       image = [UIImage imageNamed:imageName];
182
       image = [UIImage imageNamed:imageName];
173
     }
183
     }
174
-
184
+    
175
     if (image != nil)
185
     if (image != nil)
176
     {
186
     {
177
-      UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
178
-      splashViewController = [[UIViewController alloc] init];
179
-      splashViewController.view = imageView;
187
+      splashView = [[UIImageView alloc] initWithImage:image];
180
     }
188
     }
181
   }
189
   }
182
-
183
-  if (splashViewController != nil) {
190
+  
191
+  if (splashView != nil)
192
+  {
193
+    UIViewController *splashVC = [[UIViewController alloc] init];
194
+    splashVC.view = splashView;
195
+    
184
     id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
196
     id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
185
-    appDelegate.window.rootViewController = splashViewController;
197
+    appDelegate.window.rootViewController = splashVC;
186
     [appDelegate.window makeKeyAndVisible];
198
     [appDelegate.window makeKeyAndVisible];
187
   }
199
   }
188
 }
200
 }