Parcourir la source

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

This uses the proper methods for instantiating the initial view on iOS.
By utilizing these methods, we can stand up the initial view controller
from the storyboard.

See also:
https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW41
Eli Perkins il y a 7 ans
Parent
révision
36d2c7e35c
1 fichiers modifiés avec 15 ajouts et 27 suppressions
  1. 15
    27
      ios/RCCManager.m

+ 15
- 27
ios/RCCManager.m Voir le fichier

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