Why does adding custom fonts to my application's plist prevent the storyboard's initial scene from loading? - ios

I have an app with a main.storyboard with a scene correctly set as the initial view controller. When I start the app and run it, this scene comes up as expected.
My problem occurs when I attempt to add custom fonts to the project. When I edit my info.plist to include the fonts in the Fonts provided by application section and then attempt to run the app, it remains stuck on the launch screen and the initial scene from the storyboard is never loaded. If I then remove the Fonts provided ... section from my info.plist file and run it again, the initial screen loads up as expected.
What am I doing wrong here? Does it matter where in the plist the entry is (like at the top or at the bottom)?

So, I discovered that my code was hanging/freezing completely when attempting to call CGFontCreateWithDataProvider (which is a necessary part of registering custom fonts). This was being called before anything else was loaded, so the freezing on this call was preventing the main screen from ever appearing.
The "fix" (gleaned from nearly-unrelated posts) was to add this line prior to the call(s) to CGFontCreateWithDataProvider:
UIFont.familyNames() // you don't need to iterate this array or do anything with it
No more hanging, app starts up as before and custom fonts all work properly.

Related

ios - loading decoupled view from nib file

I am having difficulty with something that seems to be trivial. I am following this project https://github.com/eppz/iOS.Blog.UIView_from_Xib and trying to implement the decoupled way of loading a view from a nib file. I was not able to get the desired result in my app (nothing shows up and I get no crashes either) so I did the following:
I took the project from Github https://github.com/eppz/iOS.Blog.UIView_from_Xib
I then proceeded to duplicate the files in the "decoupled" group and name it something trivial like "decoupled2". Basically I am creating a whole new class that stands on its own with its own nib file.
I then changed all of the internal tags and class references. Then I made sure that all of the new references were pointing to this new class.
At this point I added a 6th button to the main VC and made sure to call the right method for my new "decoupled2" class when this 6th button is pressed.
PROBLEM: Everything runs but the view from nib does not show up. Debugging view hierarchy shows nothing. Clicking the 5th button still works, so I didn't break the existing code. Why won't the newly created nib file show up?
This seems rather simple, just duplicate what already works in a project that already works and it will work...or not. What am I missing? Thank you for your help.
I have spent a few days on the problem already. Lots of research but nothing of use so far.
I re-did the task and it worked this time.
Maybe restarting Xcode 8.0 was the key or something else that is under the hood.

iOS 8: Launch Screen StoryBoard appears black [single XIB file works fine]

So I tried creating a launch storyboard for my iOS 8 app using this tutorial
However, I only get a black screen when I launch my app. A single launch screen.xib file works perfectly, however, when I try to use a storyboard, it doesn't work.
I tried a storyboard with just a single view controller, but it still gives me a black screen, hence I believe the issue is with storyboard files in my setup. Any ideas?
[XCode version 6.4]
EDIT: So I just want to clarify that it is the launch screen that appears black. The main storyboard itself appears correctly when the app has finished loading
Read through the tutorial and tested it, and it doesn't say two things:
1: You'll need to add a UIViewController to your .storyboard file, and then select it as the Initial Controller.
2: If you wish to change more than just the launch screen, you'll have to go to the project settings and set the "Main Interface" to your corresponding .storyboard.
Once that is done, all you need to do is edit the UIButton/Label/etc connections to your ViewController classes.
EDIT:
For clarification, you can set a UIView as the initial controller by selecting it in it's respective storyboard file, then opening the Attributes Inspector. The option for 'Is Initial Controller" is towards the middle.
For people using UIImageView in the launch screen
Make sure that you are using the image name without the extension in the attributes inspector.
So for example, if your image file is named launcher.png, only use launcher as image name.
This will show the image as invalid (?) in the editor but will show correctly when run on device.
(Don't ask me why it works this way. Ask Apple.)
None of the answers have all the steps required, hence this exhaustive solution.
Storyboard
Start by creating the LaunchScreen.storyboard. Xcode > File > New > File... > Storyboard > LaunchScreen.storyboard and add it to all appropriate targets.
In this storyboard, create a single view controller of type UIViewController. Do all the magic your launch screen requires, then follow these steps:
LaunchScreen.storyboard > Show the File inspector > Use as Launch Screen
LaunchScreen.storyboard > View Controller > Show the Attributes inspector > Is Initial View Controller
Project > General > Deployment Info > Main Interface > LaunchScreen
Repeat for [iPhone] and [iPad]
Project > General > App Icons and Launch Images > Launch Screen File > LaunchScreen
If setup properly, your Info.plist should have LaunchScreen .storyboard, without the .storyboard under the UILaunchStoryboardName & UIMainStoryboardFile properties:
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>LaunchScreen</string>
Notes:
This is not incompatible with having legacy images for older devices using Launch Screen File > Assets.
Pay special attention to LaunchScreen.storyboard and Main.storyboard. One is used for launch, the other for your app entry point. They both need to have Is Initial View Controller set.
In the storyboard, which you are using for launching, please make sure that you had selected the option of Is initial view controller for the very single view controller present in it.
I Belive I may have had a similar issue that required something a littel different to the above answers.
I created a new launch screen in a .storyboard file, then after it not appearing I resulted to a new .xib file which still did not appear when the app was launched.
I figured out that some of the images I had on my launch screen had an Outlet Collection to an old .swift file. After removing this from the LaunchScree.xib's the launch screen worked fine.
Notice the litte warning sign in the outlet reference ->
Make sure that you set your entry point and in your general info tap make sure that you have the view set to resize from nib. Also make sure that in your general tab the start up point is set. In the deployment info.
Hope this helps
Spent way too long on this, thanks Apple! I finally discovered that I had to delete the actual UIImageView in my view controller - not just the image - in order to change to a different image. Tried renaming the images, replacing them in all different ways, deleting caches, deleting the app from the device, doing a Clean before building. The original image was gone from everywhere as far as I could see but it would still appear. Finally I added a new UIImageView on top in the view controller and this took a new image. Then I just deleted the old UIImageView and all was fine.
The solution is use the image name without the extension png.
For example, if your image file is named "img.png", only use "img".
This will show the image as invalid (?) in the editor but will show correctly on running.
This happen because the LaunchScreen.storyboard accept only images inside Assets.xcassets and the way to refer the images inside Assets.xcassets is the name of the resource without extension.
I think that use the name without extension is a workaround that work.
I had the black screen instead of my splash after localizing my app. In Localization section of the File inspector of LaunchScreen.storyboard I had only one tick for one localization. So, I added a tick for the second localization and this fixed the issue.
Answers by #SwiftArchitect and others are good, but I kept getting the black launch screen instead of my launch storyboard.
The problem ended up being that my storyboard was losing its connection to my target.
When I created it, I moved it into a different group/directory in the Project navigator, to keep things neat. BIG MISTAKE! That disconnected it from the target... it didn't matter that the group/directory it was now inside of was connected to the target!
You can tell the difference in the dropdown menu located at:
Project > General > App Icons and Launch Images > Launch Screen File
When you open that menu, you should see your storyboard as a choice to click on.
Do not type in your storyboard name manually -- that's a sign that the target membership isn't right.
I am also trying to add a launch screen, and this procedure got it to appear (thank you!), but now the app hangs there, not moving on to Main.storyboard and viewDidLoad. I have this:
Launch screen interface file base name LaunchScreen
Main storyboard file base name LaunchScreen
If I change the second LaunchScreen to Main, I do indeed get to viewDidLoad and the app's main screen, but without LaunchScreen.
Both sim and device do this. What am I missing to get to Main after LaunchScreen?

WatchKit reloadRootControllersWithNames causing error, with pageController or after push/pop

I have a basic watchkit app that loads a page based navigation of 3 interface controllers. This works well, but I'd then like to trigger an action to remove the page-control and essentially revert back to the original InterfaceController that was present when the app first loads.
// load page based control, with 3 views. this works ok
[WKInterfaceController reloadRootControllersWithNames:#[#"pageController1",#"pageController2",#"pageController3"]
contexts:#[#"data1",#"data2",#"data3"]];
// attempt to reload original interface controller, identified by storyboard id
[WKInterfaceController reloadRootControllersWithNames:#[#"myInterfaceController"] contexts:#[#{}]];
The page based navigation remove, the original navigation loads after a short spinner. However it fails to function correctly and original Actions result in this error.
Extension[6766:123665] *********** ERROR
-[SPRemoteInterface _interfaceControllerClientIDForControllerID:] clientIdentifier for interfaceControllerID:(null) not found
Is there a better way to cleanly reload the original InterfaceController?
EDIT, 2/19
It seems there are some other actions that are causing this error too. For instance, if segue to a second InterfaceController and then popController to get back, the error often appears. It is always related to a secondary call to this function.
[WKInterfaceController reloadRootControllersWithNames: contexts:]
EDIT2, 3/18
As previously mentioned, this is reproducible 100% of the time by doing the seguePush, the popController, then attempting to reloadRootControllersWithNames.
If the seguePush/popController is not done beforehand, then the reloadRootControllersWithNames will work fine.
This situation seems to be in addition to the multi->single-multi instance of this bug.
This is actually not a bug because according to Apple:
You cannot combine hierarchical and page-based interface styles. At design time, you must choose the style that best suits your app’s content and design for that style.
So unfortunately, we can't mix Hierarchical and Page-based navigation patterns within the same Watch app.
Just one of many limitations we have to deal with when developing apps for  Watch
This is a bug in WatchKit in Xcode 6.2 Beta 5. Please dupe the following radar on Apple's Bug Reporting System to help raise the priority to get this fixed.
In the meantime, a workaround that I've found can be found on the dev forums. What you can do is add a dummy interface controller to any single interface controller page set so you always have two. This will fix the error until Apple get's the bug fixed (hopefully in Beta 6). Please dupe!
I was able to solve my instance of this problem by not using popController on a pushed view controller. Instead I use a reloadRootControllersWithNames in place of the popController.
How this allows both push and paging, via an example:
Push a view controller
reloadRootControllersWithNames to return to the original controller. (The transition is not quite as animated, but is sufficient)
Create page based view controller.
reloadRootControllersWithNames to return to the original controller
Repeat 1 or 3 as needed.
This eliminates the error at the cost of non-animated popControllers, and allows partial pushing and paging. It would not allow more complex push navigation though.
There may be a better method of navigating to a sub interface controller without a push call, but I'm not aware of it on the watch yet.
None or the answers above worked for me. This problem began when I changed the icon names for the app and the watch app name. I solved it like this:
1) Click on your Watch app Target > Capabilities > make sure app Group
is in ON.
2) Make sure the App Group is selected.
3) Clic on the circled arrow Refresh icon (this will apparently just
refresh this thing if you already had it)
4-Repeat steps 1-3, but for your Watch App EXTENSION target too.
5-Click on the Scheme button (on the right side of the STOP button),
and clic on Edit Schemes.
6-Click Run > Info 7-In executable select your target (Actually it
should already be selecting but opening this window seems to
refresh the option, and wipe the error)
Apparently all these things above are not updated automatically when you change the icon name (Target names) and you have to go to those menus and open them to refresh them manually. Shame on Apple perhaps?

Full screen issue after manually creating an empty application in Xcode 6

Since xcode 6 didn't offer an empty application any more, I manually created one by deleting the Launch screen interface file and the Main storyboard file base name in the info.plist file, and deleted Main.storyboard and LaunchScreen.xib then. Considering that I'll drawing the UI by myself, I created a view controller without an xib file. But when I ran the app, there are black bars both on the top and the bottom. I checked the [[UIScreen mainScreen]bounds] and found out that the bounds was 480*320.
I've checked on google and there were suggestions like adding png pictures or creating a xib file, but I really wonder why the property bounds didn't get the right size.
I have met with this problem, it's because you delete your "Launch screen file" and didn't set in general tab "Launch image source".
So you need to make .xcassets file, after right click inside .xcassets file you create "New Launch Image" with name something like "LaunchImage" and set images for appropriate sizes. After that in general tab you set "Launch image source" property name with your "LaunchImage".
Step 1:
Step 2:
Step 3:
A better approach would be to keep the storyboard and everything else Xcode sets up for a single-view app, and then build out your UI programmaticly from the ViewController. That way, you inherit all the automagic stuff the SDK does during startup.
I can't tell you exactly what this automagic stuff is; but, I'm pretty sure your bug would go away if you adopted this approach.

Strange "Crash" with Font added to Info.plist

I've added a custom font TTF file to an app I'm making.
I've also added the UIAppFonts key to the plist, as required.
Now, when I launch the app, it hits the "app is crashing in AppDelegate" breakpoint we all know so well.
I can't figure out a way to inspect the exception, but what's stranger is that if I play it through, the app continues just fine -- even allows me to debug. On top of that, the font in question is actually loaded, so there doesn't seem to be any issue there either. Not sure where to start looking for this one.
The font file is probably not added to the target.
Please remove the white spaces from the font file name. And change name in info.plist file.
And Use the same font name which in in the .ttf file. For more information you can check NSGOD's Answer here
Do you have a symbolic breakpoint set for "objc_exception_throw"? It will break on all exceptions, including the ones that will be caught by some code's try/catch frame.
Since you are seeing it show the break at UIApplicationMain, it is likely this is the closest source code to the problem. Check the stack frames in the left column to see if there are Apple internal methods being called.
Change the slider at the bottom of the left column in Xcode to show more of the stack frames if some are hidden.

Resources