Xcode: LaunchScreen.storyboard is not showing up - ios

I'm trying to set up the launch screen and initial view of my app. However, I can't get either to show up.
I have this set up:
Am I missing a step? Shouldn't I be seeing a page with "blah" on it as the launch screen? Instead, when I run the simulator it's just black.
Also, I don't understand why my initial view isn't showing up either.
In my AppDelegate.swift file:
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.window?.rootViewController = self.rootViewController()
return true
}
private func rootViewController() -> UIViewController {
return MapViewController.init()
}
}
And my MapViewController.swift:
import UIKit
class MapViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var label = UILabel(frame: CGRectMake(0, 0, 200, 21))
label.center = CGPointMake(160, 284)
label.textAlignment = NSTextAlignment.Center
label.text = "I am a test label"
self.view.addSubview(label)
NSLog("heyyyy!!") // <----------------- doesn't get printed either, so I think I'm missing something again...
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
Sorry for the noob questions.
== UPDATE ==
I do get these 2 warnings when I build it:
file:///Users/emai/Documents/ios/Sherpa/SherpaNewYork/LaunchScreen.storyboard: warning: Unsupported Configuration: Scene is unreachable due to lack of entry points and does not have an identifier for runtime access via -instantiateViewControllerWithIdentifier:.
/Users/emai/Documents/ios/Sherpa/SherpaNewYork/LaunchScreen.storyboard:9: Scene is unreachable due to lack of entry points and does not have an identifier for runtime access via -instantiateViewControllerWithIdentifier:.

I also struggled with a launchscreen storyboard not showing up. I tried everything fix I could find to no avail. Then I cleared the cache on my Simulator and it worked! Turned out it was a simulator problem. I cleared the cache with this command in terminal: xcrun simctl erase all

It looks like you haven't set up your storyboards with an entry point. Set up the first scene you want to show as the Initial View Controller

sure, this answer is a little late. ;-) Had the some problem but i fortuitous found a quiet simple solution using the Launch Screen.storyboard created with the app automatic.
Open the App-Settings and there App Icons and Launch Images
Select Launch Screen.storyboard in the DropDown-List, even when u think, this is already selected. The display of the screen won´t change after selecting. But when restart the project, the Launch Screen was showed!
BTW to test this tidy, u can set a breakpont in the last line of
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)

After trying every other answer here, I finally deleted the LaunchScreen.Storyboard file and created a new one. This was the only thing that fixed the issue for me.

had the same problem with the launchscreen. As mentioned from Abizern, there is no ViewController allowed. If you had one only deleting this one will not be enough some times. The LaunchScreen file could still have some connections to the ViewController which is not available any more. This is a problem, too.
My fix:
Delete ViewController for LaunchScreen
Removed connections in LaunchScreen.storyboard
Removed app from Device
Reinstall
-> Worked :)

What you are missing is that a launch screen is static! It does not need a controller or anything. A controller will not do anything. For the launch screen you can design the UI only using the interface builder, not via code.
Xcode should generally tell you that, if you try to set a custom controller on the launch screen view it results in an error.

So deleting the LaunchScreen.storyboard + LaunchScreenViewController.swift files and adding a Launch Screen.xib file worked in fixing the launch screen. This makes sense to me since the launch screen should be static and not use code.
However the view is still black after the launch screen. I'll make another SO question for that.

i know it is very late but i want to share how i fixed it, if you are checking on real device then try to delete the app first, restart the handset and then reinstall the app. it will be fixed if you have followed all steps like clearing cache and settings in Target - General Tab etc.

In my case, the project navigator file filter was set to "recent". See bottom left of Xcode. I unselected recent, and the file showed up.

Easiest solution is to uninstall and reinstall the app when testing in the simulator. No need to remove and re-create LaunchScreen.Storyboard.

Related

Swift Storyboard app launches to a black screen

Hi everyone,
I'm building a Swift app using Storyboards. I've been working fine for a few months now, but all of a sudden my app won't load properly. Whenever I open it on a Simulator or my physical iPhone, the launch screen is displayed before a black screen appears.
My Mac is on macOS Big Sur Developer Beta 5 with Xcode 12 Beta 6, and my iPhone is on iOS 14 Developer Beta 5.
This happened all of a sudden and I don't recall doing anything to cause it.
Here's what I've tried so far...
Renaming the storyboard and updating the target's General tab to the new name, as well as doing the same but manually editing Info.plist
Moving the storyboard in and out of "Copy Bundle Resources"
Updating to the latest Xcode 12 beta (I'm on macOS Big Sur)
Clearing Derived Data with DevCleaner
Starting a whole new project and moving all of my code and resources over via drag-and-drop (Interesting observation: when I started a new project, I added a simple label to the default Main.storyboard and ran it on my iPhone. The label wasn't displayed.)
Adding a function to my AppDelegate to load the storyboard manually on launch
Adding various print statements in AppDelegate and my Home View Controller
AppDelegate
I've added
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "Home")
self.window.rootViewController = initialViewController
self.window.makeKeyAndVisible()
print("App launched")
to my AppDelegate. Now, when I run my app, I get
printed. I also added
override func viewDidLoad() {
super.viewDidLoad()
print("Home view loaded")
to my Home View Controller.
Now, when I run my app, I get this printed in Xcode:
2020-08-28 13:11:20.140963+0100 MY-APP[11077:1951343] libMobileGestalt MobileGestaltCache.c:166: Cache loaded with 4536 pre-cached in CacheData and 53 items in CacheExtra.
2020-08-28 13:11:20.759943+0100 MY-APP[11077:1951162] Metal API Validation Enabled
Home view loaded
App launched
Still, nothing on my iPhone. The launch screen appears, fades to black, and that's it. I'm so confused.
If anyone knows how to fix this, or something I can try, please let me know. Thank you in advance!
Make sure there a window like this present in your sceneDelegate and AppDelegate both.
class AppDelegate: UIResponder, UIApplicationDelegate {
// check for this
var window: UIWindow?
// check for this
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
}
}
If you don't want to switch to the Scene API just yet, you can also just set UIApplicationSupportsMultipleScenes to NO in the UIApplicationSceneManifest section which probably recently appeared in your Info.plist. That's what I just did, and it fixed the issue for me.
In latest version, window property is no more available in AppDelegate. Now, it is moved to SceneDelegate.swift . You can try doing as below in func scene willConnectTo:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
if let windowScene = scene as? UIWindowScene {
self.window = UIWindow(windowScene: windowScene)
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyBoard.instantiateViewController(withIdentifier: "Home")
self.window?.rootViewController = initialViewController
self.window!.makeKeyAndVisible()
}
}
Update: Also make your Main Interface under General menu is empty
Also you have to remove the <key>UIMainStoryboardFile</key><string>Main</string> and <key>UISceneStoryboardFile</key> <string>Main</string> from your Info.plist of your project.
I also faced the same issue. The original question says,
"This happened all of a sudden and I don't recall doing anything to cause it."
This is exactly what happened to me and following is how I solved the issue.
In Main.storyboard, there is an entry point to the app which is visually depicted as an arrow pointing to the Navigation Controller. Once the issue showed up, I noticed that this arrow is now somehow missing and Is Initial View Controller checkbox in the View Controller section of the Attribute Inspector tab in the Inspectors pane is now unchecked.
The issue was resolved when I checked the Is Initial View Controller checkbox mentioned above(The arrow in the storyboard navigation controller also reappeared upon checking this). Below is an image of xcode after solving the issue to help get a better understanding.
This is an image showing the Navigation Controller and Inspectors pane after the issue was fixed.
Hope someone finds this useful.

Storyboard not deleting in Xcode 11

I usually build UI programatically but for some reason after updating to Xcode 11, not able to remove storyboard or remove the reference. It keeps throwing an error saying storyboard missing. Usually I delete the main and go to project settings and remove the Main keyword text as well. I then delete the viewController, add a new viewController like HomeViewController and use the following code in app delegate.
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow()
window?.makeKeyAndVisible()
let nc = UINavigationController(rootViewController: HomeViewController())
window?.rootViewController = nc
return true
}
I follow the exact same steps that I used to follow in previous Xcode versions and it used to work (without deleting the storyboard file itself). As long as I added the above code. Now doesn't seem to be the case. If I delete the default ViewController file and say add a new HomeViewController File and add the above code, throws an error saying storyboard is missing or storyboard does not contain HomeViewController.
You don't say, but I'm assuming you're creating a new project with an iOS 13 target? If not, you can ignore this :-)
In XCode 11 for a new iOS 13+ project they changed the way initiating a UI from code works. It no longer takes place within the AppDelegate but in the SceneDelegate.
After I'd spent far too long working out what was going on I wrote it up in a blog post with the idea it may help someone else. Rather than rehashing it all, I'll link to it:
XCode 11 New Project Without Storyboard

Why does adding iOS AdMobs GADBannerView cause sigabrt in AppDelegate (Swift)?

I'm having trouble getting AdMob advertising working in my iOS app.
I'm getting a specific error which I will show you below, but first here is what I've tried.
Here's What I've Tried
Once I got the error in my main app I retrieved the official BannerExample and got it running successfully. BannerView example app runs and I see the ad appear in the app while it's running on my iPhone 5s simulator.
I've done all manner of pod update to insure I have the exact new versions of all required packages and keep in mind that the app builds with no problems.
I've debugged it down to a single line of code that I will show you below.
Now that you know I've done quite a bit of work, take a look at what is happening.
The App Crash
The exact error is :
CYaPass[13155:433036] [MC] Reading from private effective user
settings. Google Mobile Ads SDK version: afma-sdk-i-v7.15.0 2016-12-04
14:37:26.046 CYaPass[13155:432944] -[UIView loadRequest:]:
unrecognized selector sent to instance 0x7f8bf4546090 2016-12-04
14:37:26.055 CYaPass[13155:432944] *** Terminating app due to uncaught
exception
This is not the normal sigabrt on AppDelegate error.
I have tried all the normal things related to StoryBoard and here is an image which shows you I don't have any undefined items that are blowing this up. Plus, I'll show you that when i remove the one line of AdMob code the app will run normally.
You can see that I do have two outlets defined on the UIView that I'm attempting to use for the BannerView. That's so I could test it when I remove the one line of AdMob code.
You can also see those outlets on the SettingsController
You can see them in my actual controller code which looks like the following:
#IBOutlet weak var AdMobs: GADBannerView!
#IBOutlet weak var SuperView: UIView!
func loadAd(){
AdMobs.adUnitID = "ca-app-pub-3940256099942544/2934735716"
AdMobs.rootViewController = self
AdMobs.load(GADRequest())
SuperView.backgroundColor = UIColor.black;
}
I separated those lines into the loadAd() func so I could test them from different locations, but it's the same code that the official BannerExample uses and calls in viewDidLoad() func.
Small Test On UIView
Then, you see I also do a little work on the exact same UIView (SuperView) where I set the backgroundColor to black.
That was to convince myself that it wasn't just becuase I'd attached an outlet to that UIView. But that code works fine, if I simply comment out the three lines before it.
Here, I'll run it and show you the output. Just before I do that, here's my AppDelegate application constructor which doesn't change. It is really a copy of the exact official BannerExample:
import Firebase
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate{
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FIRApp.configure()
GADMobileAds.configure(withApplicationID: "ca-app-pub-myapp-hiddenforpublicConsumption")
return true
}
Now, I'll change change loadAd() to look like the following and run again:
func loadAd(){
//AdMobs.adUnitID = "ca-app-pub-3940256099942544/2934735716"
//AdMobs.rootViewController = self
//AdMobs.load(GADRequest())
SuperView.backgroundColor = UIColor.black;
}
Obviously, the only change is that I commented those three lines. Here's what it looks like when it runs.
Tabbed View Application
By the way, this is a tabbed app. So the app comes up, I click on the Settings tab and you can see that the altered code in loadAd() runs and turns the background of the UIView black.
Main Point : Specific Code Causes Problem
Now, let me show you that if I uncomment just that first line of Banner Ad code then the app crashes in the AppDelegate.
Here's the altered loadAd() again:
func loadAd(){
AdMobs.adUnitID = "ca-app-pub-3940256099942544/2934735716"
//AdMobs.rootViewController = self
//AdMobs.load(GADRequest())
SuperView.backgroundColor = UIColor.black;
}
Again, you can see that I've only uncommented the one line that sets the adUnitId on the GADBannerView. This is the exact same code that the BannerExample uses. It even uses the same test unitId which is free for everyone's testing. Also, even if you change that unitId to a invalid value the app does not crash, the ad just doesn't show up.
Here's The Result
Debugging Shows Exact Line of Code
I can step into the code and it is exactly on that loadAd() line we just added when this error occurs (shown below for clear reference):
AdMobs.adUnitID = "ca-app-pub-3940256099942544/2934735716"
Only Difference : Tabbed View -- Is That the Issue?
The only effective difference is that my app is based upon the tabbedview.
Does anyone know why this occurs?
I've been trying everything for almost 2 days now. Any help is appreciated.
Oh, the agony...I finally found the answer.
First of all, here you can see I've gained success.
Type of View Must Be Changed
If you go to storyboard and examine that UIView you will see it looks like the following:
However, it kind of makes sense that because it is not a GADBannerView that the error we got looks like:
[UIView setAdUnitID:]: unrecognized selector sent to instance
That was the clue that got me to the answer.
You have to change the value to a GADBannerView (just type it in the box over UIView):
I also confirmed that in the official example that the type is set properly there.
That's about 36 hours I'll never get back.
I missed that step in the initial documentation so this is "error between chair and keyboard".
If anyone else has this same problem and doesn't know what's going on, I had a different problem with a similar error.
Go to the View for the ad, and go down to where it says Label. Change that to your view's name, it worked for me.
Also make sure module is empty, and inherit module from target is unticked.

Could not successfully update network info during initialization

I get the above mentioned issue all the time when I first launch the app in the day.
When I first launch the app, I make server calls to get some data and then play animation video. Server calls is in a separate thread than main UI Thread.
Is it something to do with Network Reachability or the animation video ? I think the first part is the major issue but cannot recreate this all the time.
Has anyone experienced the issue ?
Below is the code when I first launch the app.
override func viewDidLoad() {
super.viewDidLoad();
self.navigationController?.navigationBarHidden = true;
self.view.backgroundColor = UIColor.whiteColor();
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { () -> Void in
Items.setup(); //AFNetworking call
};
animationViewController.delegate = self;
animationViewController.view.autoresizesSubviews = true;
animationViewController.view.autoresizingMask = [.FlexibleLeftMargin, .FlexibleRightMargin];
animationViewController.view.center = CGPointMake(self.view.bounds.size.width / 2, self.view.bounds.size.height / 2);
self.view.addSubview(animationViewController.view);
}
I have resolved this issue in Xcode 9.1 with below steps.
1.Select Simulator
2.Select Debug from top menu items.
3.Select Location from Debug menu list.
4.Select Apple location.
Check if you have an exception breakpoint to capture "All Exceptions" in breakpoint navigator. This fixed it for me.
Was experiencing this too, fixed it by giving the simulator a default location. It may be a code smell so watch how you handle the new location permissions in iOS11.
I had similar problem. Turns out in the App/Capabilities, I have Wireless Accessory Configuration with some red warnings. Click the button automatically solved the problem.
Not sure if it would work for you. I am using Xcode 8.
Issue: same with Xcode 9.0 iOS11.
Resolution: new iOS requires you to manually turn on privacy for new deployment apps. Upgrades of the app is not needed. Following these steps:
(1) iPhone "Settings" icon: click
(2) "Privacy": click
(3) "Location Services": click
(4) [Your app]: click on your app
(5) "While Using the App": click
You might have overrided loadView() without calling super method.
Change
override func loadView() {
}
To
override func loadView() {
super.loadView()
}

Issues with Today Widget extension

I have a Today Widget for my app, however I have been told about an issue with it.
Basically, what seems to be happening (I can't test this for myself) is that the widget will sometimes just display 'unable to load' and other times it will just display with a height of 0.
I can't really see why this is happening. I've tested it out on my device and the simulator for weeks now and have never ran into this issue.
I was wondering if it could possibly be down to the refresh code:
func widgetPerformUpdateWithCompletionHandler(completionHandler: ((NCUpdateResult) -> Void)!) {
// Perform any setup necessary in order to update the view.
var defaults = NSUserDefaults(suiteName: "group.AffordIt")
var newCheck = defaults.boolForKey("new")
if newCheck == true {
completionHandler(NCUpdateResult.NewData)
} else {
completionHandler(NCUpdateResult.NoData)
}
}
'newCheck' is true whenever something changes within my app that needs to be displayed in the widget.
Does anyone know what the possible causes of these issues are?
"unable to load" message appears if your extension crashes often. You can try to re-enable it by removing and adding the extension again.
Are you using your own view controller and xib instead of using storyboard? If yes, it is probably that you didn't set the preferredContentSize in your view controller.
try to put the following code in the init function of ur view controller:
self.preferredContentSize = CGSizeMake(320, 100);
I have just began the extension programming today so I am not sure is it really helpful for u or not. Here is the result in my own widget:
Press Edit button in today extensions
Remove your extension
Add your extension again.

Resources